4

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

}
5
  • What does netstat -pan say - is nginx listening at tcp level? Jun 15, 2012 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, 2012 at 4:15
  • Does anything show up in error log? What does nginx -t says?
    – kworr
    Jun 15, 2012 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, 2012 at 15:07
  • Did you check the firewall? (sorry about the stupid question!) Jun 19, 2012 at 4:22

1 Answer 1

2

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

fastcgi_param HTTPS on;

5
  • Any reason on why it was downvoted? Appreciate an alternative view on my answer. Jun 19, 2012 at 6:36
  • Thanks for the comment @Pothi I will try this and follow up soon
    – jnolte
    Jun 19, 2012 at 23:32
  • @jnolte Did it work? Aug 29, 2012 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, 2012 at 20:56
  • Oh, that's interesting to hear. Thanks for sharing what worked for you. Aug 30, 2012 at 7:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .