Tuesday, October 3, 2017

nginx reverse proxy not replacing the application IP

I have an application sitting behind a nginx and obviously not working as desired. So i tried to replicate in my local environment.



Background
The webapplication is running fine on its own and returns a /static/index.html as the default page.
e.g. on accessing http://localhost:7777/ returns /static/index.html and all works fine. {http://localhost:7777/static/index.html}




Problem
When i try to access the same app behind a proxy,it doesn't work. On accessing
http://localhost/app { the localhost is name of the server default in nginx } the app returns as usual /static/index.html and gets rerouted tp http://localhost/static/index.html and returns 404.



Desired situation
Even if the app is behind a proxy, i should be able to see the app. Instead of http://localhost/static/index.html the URL should be similar to http://localhost/localhost:7777/static/index.html



nginx.conf




server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}

location /app/ {
proxy_pass http://localhost:7777/;
proxy-redirect off;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_buffering off;
client_max_body_size 0;

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_pass_header Set-Cookie;
proxy_pass_header P3P;
}


Any ideas how can this be achieved?

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...