Friday, April 22, 2016

Nginx proxy pass works for https but not http



I want to redirect HTTP traffic and HTTPS traffic to a backend Flask application and I have the snippet below in my nginx.conf which works for https but not for http





server {
listen 80;
listen 443 ssl;
ssl_certificate /usr/local/nginx/server.crt;
ssl_certificate_key /usr/local/nginx/server.key;

location / {
proxy_redirect off;
proxy_cache off;
proxy_pass http://127.0.0.1:5000;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}


Does anyone have any pointers? Is there something obvious in the config file snippet or did I install Nginx wrong?



Thanks!



Answer



I installed nginx on my Redhat16 machine from yum. After I removed the contents of the etc/nginx/conf.d directory, everything worked as expected. It seems something in that directory was overruling the http proxy_pass.


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...