| tags:admin https linux magento nginx sysadmin categories:Tech

Configure Nginx for Magento HTTPS

I had an issue with Magento 1.6 entering a redirect loop when transitioning from HTTP to HTTPS. There are a few other articles out there on this issue, and from what I gather it has to do with Magento being case sensitive when reading the HTTPS header. Here’s what I did to fix it.

In /etc/nginx/nginx.conf:

http ... {
    map $scheme $fastcgi_https {
        default off;
        https on;

This uses Nginx’s Map module to set a variable $fastcgi_https. The variable is set to “off” by default, and “on” for HTTPS connections. We then use the variable to set a FastCGI parameter.

In the location handler for PHP scripts in /etc/nginx/sites-enabled/www.yoursite.com:

server ... {
    location ~ \.php(|/.*)$ ... {
        fastcgi_param HTTPS $fastcgi_https;

Be sure to reload your Nginx configuration to put the changes into action. For some more in-depth information on the subject, see this page in the Magento Wiki: Configuring Nginx for Magento