Fix Nginx redirects to url:port when accessing url without slash

When accessing http://example.com/somefolder, you might get http://example.com:8080/somefolder (8080 is the port you are listening) instead, since your are missing a slash in the end. One may use rewrite to deal with it. However, a simple build-in solution is port_in_redirect off. An example is as follow:

1
2
3
4
5
6
7
8
9
10
11
server {
listen 8080;
server_name example.com;

port_in_redirect off; ## adding this

location / {
root /var/www/example.com;
index index.html;
}
}