claylo

Scroll to Top

SSL, php-fpm and nginx

Like many switching to the nginx/php-fpm combo, I ran into a situation with some PHP scripts that relied on $_SERVER[“HTTPS”] having a value of ‘on’. As of nginx 1.0.4, this isn’t provided out of the box. Of course, the rest of the $_SERVER[“SSL_*”] values that are present under Apache and mod_php (or php-fpm) aren’t available either.

The closest approximation I could come up with to Apache’s mod_ssl +StdEnvVars for nginx is this: create a file in your nginx config directory (commonly /usr/local/nginx/conf) called fastcgi_ssl.conf. Add the following to it:


# Provide as much of Apache's SSL +StdEnvVars data as possible.
fastcgi_param HTTPS                 on;
fastcgi_param SSL_PROTOCOL          $ssl_protocol;
fastcgi_param SSL_CIPHER            $ssl_cipher;
fastcgi_param SSL_SESSION_ID        $ssl_session_id;
fastcgi_param SSL_CLIENT_VERIFY     $ssl_client_verify;

# _SERVER entries for these will be empty unless you
# rely on client-side certs you've issued
#fastcgi_param SSL_CLIENT_CERT       $ssl_client_cert;
#fastcgi_param SSL_CLIENT_RAW_CERT   $ssl_client_raw_cert;
#fastcgi_param SSL_CLIENT_S_DN       $ssl_client_s_dn;
#fastcgi_param SSL_CLIENT_I_DN       $ssl_client_i_dn;
#fastcgi_param SSL_CLIENT_SERIAL     $ssl_client_serial;

Include this file only inside server {} blocks that are configured for SSL use in nginx, and you’ll find that a environment checks for HTTPS work a lot better from within PHP.

July 14, 2011
comments
11 notes

Share
http://tmblr.co/ZajbZy7637iU
SSL, php-fpm and nginx
phpnginxtech

11 notes

  1. transientyou83 likes this
  2. nhmortgagebroker likes this
  3. mamortgageexpert likes this
  4. loganabbott likes this
  5. claylo posted this

COMMENTS

< Previous post Next post >

 

Theme by Pixel Union

  • Profile
  • Pages
  • Likes
  • About me

    Jexy founder, Mashery co-founder, father, husband, recovering yak shaver.

  • Connect with me

    • Facebook
    • Vimeo
    • Flickr
    • Instagram
    • Github
  • RSS
  • Archive

Pages:

  • Presentations

Stuff I Like

  • Post via lessig
    A time for silence

    A week ago today, Aaron gave up. And since I received the call late Friday night...

    Post via lessig
  • Photo via daneschmidtphotography

    Spending the day chillin with Lucifer Michael Jackson Batman Schmidt…

    Photo via daneschmidtphotography
  • Photo via brycedotvc

    via waitingformyatonementt

    Photo via brycedotvc
  • Photo via daneschmidtphotography

    Guarding the big door. with @emilyeahh

    Photo via daneschmidtphotography
  • Quote via brycedotvc
    “Live in the future, then build what’s missing.”
    — PG
    Quote via brycedotvc