2

I have already tried suggestions mentioned in:

Hide port in Nginx reverse proxy redirection

but it does not help me.

I have done nginx reverse proxy for my django+gunicorn application and it is open on port 8000. I can access a machine name as http://some_machine:8000 to see my app running. I have mapped localhost running on that machine with machine name using Nginx reverse proxy. I want to hide the port and in url would like something like http://some_machine/zmk instead of http://some_machine:8000/zmk.

I am writing the below content to my /etc/nginx/conf.d folder:

upstream zms {    
  ip_hash;    
  server zms:8000;    
}

# portal

server {    
  location /zmk {    
        proxy_pass http://zms/;    
        # proxy_redirect http://some-machine:8000/ http://some-machine/zmk;    
        port_in_redirect off;    
        # autoindex on;            
        proxy_set_header Host $host:$server_port;    
        proxy_set_header X-Real-IP $remote_addr;    
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    
        proxy_set_header   X-Forwarded-Proto $scheme;    
    }
  listen 8000;    
  server_name localhost    
  server_name_in_redirect off;    
}

I am not understanding what am I doing wrong? I have also tried copying the above content to /etc/nginx/site-available folder.

1 Answer 1

2

Change your listen statement to listen 80 instead. That way your nginx server will listen on port 80 and proxy the traffic to port 8000.

6
  • On port 80 my other ASP.NET app is serving angular static files. If I change it to listen 80, my django app stops working. Sep 13, 2018 at 14:31
  • Then put that ASP.NET app also behind your nginx server. How else do you suggest to hide the port number if you can't use port 80?
    – Tommiie
    Sep 13, 2018 at 14:50
  • ASP.NET is also running behind nginx that is where it is serving static files through port 80 Sep 13, 2018 at 15:08
  • If they are both behind nginx you can have them both work on port 80....
    – Tommiie
    Sep 14, 2018 at 6:48
  • thanks, how do I do that ? Sep 14, 2018 at 8:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.