I am trying to configure nginx but I cannot get it to work despite of my multiple attempts. What I need is:
- port 80,
/download
is served by nginx - port 80, anything else is redirected to the same machine, port 8080
This works fine, but now I need that only in the case of the root (http://myhost/) the client is redirected to the default app at /Games
. My current configuration is wrong and redirects me in an infinite loop. I got some ideas from here but couldn't make it work. Examples of the redirections:
ex1: http://myhost/ --> http://myhost/Games --> http://localhost:8080/Games
ex2: http://myhost/Books --> http://localhost:8080/Books
I have tried
location / {
proxy_pass http://localhost:8080/Games;
}
But this seems to act on everything (ex: /Books, /XYZ, ...). I think a redirection when the exact root is specified is the cleanest.
Also, I need to replicate this on the HTTPS. I suppose this will also work over the "stream" element.
nginx.conf:
http {
server {
listen 80;
root /home/www/;
location = / {
return 301 http://$host/Games;
}
location / {
proxy_pass http://localhost:8080;
}
location /download/ {
....
}
}
}
stream {
server {
listen 443;
...
}
}