1

I have a Debian server running nginx with the following nginx configuration:

server {
  listen 80 default_server;

  root /var/www/serviceserver1;
  index index.html index.htm;      

  location /api {
        proxy_redirect          http://localhost:3001/  /api;
        proxy_pass_header       Server;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Scheme $scheme;
        proxy_set_header        Host $http_host;
        proxy_set_header        X-NginX-Proxy true;
        proxy_connect_timeout   5;
        proxy_read_timeout      240;
        proxy_intercept_errors  on;

        proxy_pass              http://localhost:3001;
    }

    location /graphql {
        proxy_redirect          http://localhost:3001/  /graphql;
        proxy_pass_header       Server;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Scheme $scheme;
        proxy_set_header        Host $http_host;
        proxy_set_header        X-NginX-Proxy true;
        proxy_connect_timeout   5;
        proxy_read_timeout      240;
        proxy_intercept_errors  on;

        proxy_pass              http://localhost:3001;
   }

  # Root route
  location = / {
    try_files $uri /landing/index.html;
  }

  # admin routes
  location /admin {
    try_files $uri $uri/ /admin/index.html;
  }

  # analytics routes
  location /analytics {
    try_files $uri $uri/ /analytics/index.html;
  }

  # landing routes
  location /landing {
    try_files $uri $uri/ /landing/index.html;
  }

  # Any other route default to landing
  location / {
    try_files $uri $uri/ /landing/index.html;
  }
}

Works very fine in my LAN.

I'm now setting up an external connection to the Internet. I'm using a TP-LINK TL-R470T+ with a Virtual Server configuration to redirect my ports (8000 from outside goes to 80 internally):

enter image description here

When I try to access my browser from outsite, I use:

http://170.80.200.100:8000/landing/

All fine.

My problem arises when I need to switch pages on my Web applcation. Every time I navigate, I'm getting back to the url without the port, like (Ip address not the real one):

http://170.80.200.100/landing/

http://170.80.200.100/admin/

or

http://170.80.200.100/analytics/

So, every time I navigate to a different page I need to type the :8000 by hand in the address bar, something impractical.

How can I setup my NGINX file to keep the original port back (:8000) on every URL acessed, when I'm accessing from the internet?


Note that I've tried changing the internal port from 80 to 8000 and application worked perfectly when accessed on that port from the internal LAN, but I cannot keep it set to 8000 internally and need it set to 8000 externally.

  • Are you asking how to get Nginx to edit your html files and add the :8000 string to any links? You may be able to use sub_filter. – Richard Smith May 10 at 13:07
  • I'm not asking that, the opposite. I need to make the system work on port redirection without touching my html files... – Mendes May 10 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.