How to setup Nginx to display a website served by an internal Python server

Viewed 15

I'm using Nginx as a reverse proxy for several web services and it works well, however, now I need to redirect the input to this server to display a website. This web runs on an internal server, localhost:51000, and its main page is localhost:51000/login. The server runs under Python. I would like to use an arbitrary URI to access this website from any computer but I'm not able to configure Nginx for this purpose. Needless to say, I have followed various examples and instructions found on the web and in the nginx documentation.

For example, using the following configuration:

server {
    listen 443 ssl;
    server_name myweb.com;
  
    server_tokens off; 
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
  
    ssl_certificate ...;      
    ssl_certificate_key ...;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ...             

    location / {
        root   html;
        index index.html index.php;
    }

    location /vis2 {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
            
        rewrite ^/vis2(.*) /$1 break;
        proxy_pass http://localhost:51000/login;
    }

writing myweb.com/vis2 on a web browser the server redirects to https://myweb.com/login, and the result is a 404 code because it expects to find the login file in the root of myweb.com

Instead, if I use this other configuration:

    location /vis1 {
        rewrite ^/vis1(.*) /$1 break;
        proxy_pass http://localhost:51000/login;
        proxy_redirect off;     
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    

writing myweb.com/vis1 on a web browser the server redirects to https://localhost:51000/login, and this is not accessible from outside the server.

I wonder what am I doing wrong or maybe it is not possible. Any advice?

Thanks in advance

0 Answers
Related