Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

I believe you need a separate server block for HTTP. For example:

server {
listen 80;

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;
}
}

You would then remove listen 80; from the existing server block.

share|improve this answer
    
According to the Nginx documentation, you can have a single block. nginx.org/en/docs/http/configuring_https_servers.html –  Spaceghost Oct 10 '12 at 19:43
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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