Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am in the process of trying to configure a Server with https and for some reason it seems the requests are not hitting nginx at all. I have everything working properly but once I go to enable ssl it gives me an will not accept any requests on port 443 (connection timeout). Does anyone know how I can begin to debug this issue? I am using all of the same logic I have used on previous servers.

Nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    port_in_redirect off;
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

domain.conf in conf.d:

   server {
  listen 80;      
  server_name domain.com;
  location / {
    rewrite ^ https://$server_name$request_uri? permanent;   
  }
}                  

server {         
  listen 443; 
  server_name domain.com;
  root /var/www/;
  ssl on;
  ssl_certificate /etc/ssl/domain.com.combinded.crt;
  ssl_certificate_key /etc/ssl/domain.com.key;
  index index.html index.htm index.php;


  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  location ~ \.php$ {
    fastcgi_intercept_errors on;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
  }

  # BEGIN W3TC Page Cache cache
  location ~ /wp-content/w3tc/pgcache.*html$ {
    add_header Vary "Accept-Encoding, Cookie";
  }
  location ~ /wp-content/w3tc/pgcache.*gzip$ {
    gzip off;
    types {}
    default_type text/html;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Content-Encoding gzip;
  }
  # END W3TC Page Cache cache
  # BEGIN W3TC Browser Cache
  gzip on;
  gzip_types text/css application/x-javascript text/x-component text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
  location ~ \.(css|js|htc)$ {
  }
  location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
  }
  location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
  }
  # END W3TC Browser Cache
  # BEGIN W3TC Page Cache core
  rewrite ^(.*\/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 last;
  set $w3tc_rewrite 1;
  if ($request_method = POST) {
    set $w3tc_rewrite 0;
  }
  if ($query_string != "") {
    set $w3tc_rewrite 0;
  }
  if ($http_host !~ "XX.XXX.XX.XX") {
    set $w3tc_rewrite 0;
  }
  set $w3tc_rewrite3 1;
  if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|\/feed\/|wp-.*\.php|index\.php)") {
    set $w3tc_rewrite3 0;
  }
  if ($request_uri ~* "(wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") {
    set $w3tc_rewrite3 1;
  }
  if ($w3tc_rewrite3 != 1) {
    set $w3tc_rewrite 0;
  }
  if ($http_cookie ~* "(comment_author|wp\-postpass|wordpress_\[a\-f0\-9\]\+|wordpress_logged_in)") {
    set $w3tc_rewrite 0;
  }
  if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.2\.4)") {
    set $w3tc_rewrite 0;
  }
  set $w3tc_ua "";
  set $w3tc_ref "";
  set $w3tc_ssl "";
  set $w3tc_enc "";
  if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc _gzip;
  }
  set $w3tc_ext "";
  if (-f "$document_root/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl.html$w3tc_enc") {
    set $w3tc_ext .html;
  }
  if ($w3tc_ext = "") {
    set $w3tc_rewrite 0;
  }
  if ($w3tc_rewrite = 1) {
    rewrite .* "/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl$w3tc_ext$w3tc_enc" last;
  }
  # END W3TC Page Cache core

}
share|improve this question
    
What does netstat -pan say - is nginx listening at tcp level? –  rackandboneman Jun 15 '12 at 0:00
    
Thanks for some insight @rackandboneman it looks like it is listening here are the contents. gist.github.com/2934638 –  jnolte Jun 15 '12 at 4:15
    
Does anything show up in error log? What does nginx -t says? –  kworr Jun 15 '12 at 8:07
    
From nginx -t: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful nothing in the error log. –  jnolte Jun 15 '12 at 15:07
    
Did you check the firewall? (sorry about the stupid question!) –  Pothi Jun 19 '12 at 4:22
add comment

1 Answer

On your location ~ \.php$ block, please include the following line, if it doesn't already exist in fastcgi_params file...

fastcgi_param HTTPS on;

share|improve this answer
    
Any reason on why it was downvoted? Appreciate an alternative view on my answer. –  Pothi Jun 19 '12 at 6:36
    
Thanks for the comment @Pothi I will try this and follow up soon –  jnolte Jun 19 '12 at 23:32
    
@jnolte Did it work? –  Pothi Aug 29 '12 at 13:39
    
This did not work. I actually ended up using a WP plugin to force https on certain urls and not others. It was the easiest fix. –  jnolte Aug 29 '12 at 20:56
    
Oh, that's interesting to hear. Thanks for sharing what worked for you. –  Pothi Aug 30 '12 at 7:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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