Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have nginx configured to be my externally visible webserver which talks to a backend over HTTP.

The scenario I want to achieve is:

  1. Client makes HTTP request to nginx which is redirect to the same URL but over HTTPS
  2. nginx proxies request over HTTP to the backend
  3. nginx receives response from backend over HTTP.
  4. nginx passes this back to the client over HTTPS

My current config (where backend is configured correctly) is:

server {
        listen       80;
        server_name  localhost;

        location ~ .* {
            proxy_pass http://backend;
            proxy_redirect http://backend https://$host;
            proxy_set_header Host $host;

My problem is the response to the client (step 4) is sent over HTTP not HTTPS. Any ideas?

share|improve this question
I think you should accept the second answer, because it provides an actual example for configuring this. – Andy Jun 15 at 1:49
up vote 1 down vote accepted

The type of proxy you are trying to set up is called a reverse proxy. A quick search for reverse proxy nginx got me this page:

In addition to adding some useful features like an X-Forwarded-For header (which will give your app visibility into the actual source IP), it specifically does:

proxy_redirect off

Good luck! :)

share|improve this answer
Thanks for your response - the link was indeed very helpful. I think I've solved my problem by splitting it up - I configured a redirect for all HTTP requests on port 80 to HTTPS on port 443. I then configured a new server in the config for 443. I was previously trying to do this all same place. – Mike May 26 '10 at 9:58

I'm using the following config in production

server {

    rewrite ^(.*) https://$server_name$1 permanent;

server {

    root   /vhosts/;

    ssl                  on;
    ssl_certificate      /etc/pki/nginx/;
    ssl_certificate_key  /etc/pki/nginx/;

    ssl_prefer_server_ciphers on;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
    ssl_dhparam /etc/pki/nginx/dh2048.pem;

    # intermediate configuration. tweak to your needs.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    location / {
        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-Forwarded-Proto https;
share|improve this answer

Your Answer


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.