Search code examples
linuxunixnginxwebservernginx-config

How to remove the port number from URL in a nginx site


In an URL, I see something like: http://example.com:8000/page. Even though I manage to access the site by typing URL without the port, it is added there when I go to any sub-page.

I used to have a Python-based web server instead of nginx, it worked awfully, however, the port number was never there. This is why I still hope there is a way to hide a non-standard port (without changing it to standard) because the Python web server didn't show one.

I redirect port 80 >> 8000, by the way.

Is there a feature in the nginx config to hide non-standard port from a site? If no, maybe some other method?

My config:

server {

  listen 8000;

  access_log /logs/access.log;
  error_log /logs/error.log;

  index index.html;
  server_name example.com;

  error_page 404 errors/404.html; 

  location / {
    try_files $uri $uri/ =404;
  }

}

Solution

  • I've just figured out that

    port_in_redirect off;
    

    solves it.