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 :

    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

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;

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


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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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