nginx 1.8.0 ssl configuration root location behaving unexpectedly

I bump into this problem. I recently install nginx 1.8+ on a centos 6.7 along with PHP-FPM (5.3+). The installation was fine and setting up the virtual host was okay too but when I create a secure site and forward my http to https here comes the trouble. The page says 404 not found. When I check the error logs of nginx I found out it is looking on different directory and not with the directory I specified.

Here is the error logs

2016/01/22 21:54:29 [error] 4205#0: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 173.245.48.185, server: subdomain.example.com, request: "GET / HTTP/1.1", host: "subdomain.example.com"

The nginx using SSL use the /etc/nginx/html/ and not my defined root which is /srv/www/default-www directory. Below is my SSL configuration help me and kindly correct the error I made. Thanks in advance 🙂

    server {
     listen 80;
     server_name subdomain.example.com;

     if ($http_cf_visitor ~ '{"scheme":"http"}') {
        return 301 https://$server_name$request_uri;
     }

    }


    server {
    listen 443;
    server_name  subdomain.example.com;
root /srv/www/default-www/;
server_tokens off;


#access_log  /var/log/nginx/log/subdomain.example.com.access.log  main;

gzip on;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;


ssl_certificate      /etc/nginx/ssl/server.crt;
ssl_certificate_key  /etc/nginx/ssl/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout  5m;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
ssl_prefer_server_ciphers   on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";

location / {
 try_files $uri $uri/ /index.php;
 #index  index.php index.html index.htm;
}

location ~ /(cgi-bin|file_upload|file_assets) {
  deny all;
  return 404;
}

location = /favicon.ico {
  log_not_found off;
}

error_log /var/log/nginx/subdomain.example.com-error.log warn;    
error_page   500 502 503 504  /50x.html;

location = /50x.html {
    root   /usr/share/nginx/html;
}

location ~ \.php$ {
    fastcgi_pass   unix:/var/lib/php/socket.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
   }
 }

Please note I change the domain name and provided an example only. Where in my configuration is wrong? Kindly correct me if you had this problem before or any solution you can offer for a newbie like me.

Answer

You do not appear to have SSL mode enabled. You have all of the SSL configuration but have not switched on SSL. This is achieved in the listen or ssl directives.

listen 443 ssl;

Why that would cause the side-effect you are observing – I have no idea.

See this document for more information.

Attribution
Source : Link , Question Author : Edang Jeorlie , Answer Author : Richard Smith

Leave a Comment