1

I've got a problem configuring nginx and apache on a Debian 8 machine. I use nginx s reverse proxy, which is setup to run on HTTPS (and it works like a charm). But, when requests are sent to Apache, the $_SERVER['HTTPS'] is empty, although it should be "ON" (anyway, that's what i'd like to achieve) ? Here is my apache config :

<VirtualHost 127.0.0.1:8080> ServerName shop.mywebsite.com ServerAdmin webmaster@localhost DocumentRoot /var/www_shop ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined LogLevel debug <Directory "/"> Require all granted </Directory> </VirtualHost> 

And here is my nginx congif, part on proxy pass :

 location ~ \.php { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Original-Request $request_uri; add_header Front-End-Https on; proxy_pass http://127.0.0.1:8080; } 

Any help, any clue, appreciated ;) Thanks, Olivier.

1 Answer 1

1

The HTTPS state you are looking for is set if the connection to the web server is over HTTPS. As your are looking for this value in Apache but only Nginx is handling the request via HTTPS and Apache getting requested via HTTP by Nginx, the status must be no-HTTPS.

In your proxy configuration of Nginx, you will set already some additional header. What you have to do is, check for these header in Apache and overwrite HTTPS status flag

Therefore you have to install and activate mod_setenvif in Apache and add following to your Apache config:

<IfModule mod_setenvif.c> SetEnvIf X-Forwarded-Proto "https" HTTPS=on </IfModule> 

In your Nginx config one setting is missing. As long as your Apache does not have multiple virtual hosts, it doesn't matter but I recommend to add following to your Nginx config:

proxy_http_version 1.1; 

By setting this Nginx speaks to Apache in HTTP/1.1. The default is HTTP/1.0.

1
  • Yes, thanks so much, been looking around for a few days not finding a way to achieve this, and you come with perfect solution ! Commented Sep 6, 2017 at 6:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.