Monday, May 27, 2013

Getting PHP HTTPS-Detection Working in Nginx

when I print_r($_SERVER) variable, I did not see the $_SERVER['HTTPS'] key. You will need to tell Nginx to set the HTTPS parameter when it hands the request off to the FastCGI wrapper.

Add this line:
fastcgi_param HTTPS on;

To this block in /usr/local/etc/nginx/nginx.conf:
location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    #NOTE: You should have "cgi.fix_pathinfo = 0" in php.ini
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_param HTTPS on;
                    fastcgi_intercept_errors on;
                    #fastcgi_pass 127.0.0.1:9000;  #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
                    fastcgi_pass unix:/tmp/php-fpm.sock;
            }

Reference:
http://blog.chrismeller.com/getting-php-https-detection-working-in-nginx

No comments: