Why do I get a 404 for my index.page in my http/https nginx setup?

frequent asked:

I’m using WPN-XM (stack with Nginx, MariaDB, PHP and OPENSSL) and am trying to setup OpenSSL in a HTTP/HTTPS server. I’m following the instructions from NGINX here and my server starts/stops without errors.

This is my nginx.conf with the “double server”:

server {
    listen              80;
    listen              443 ssl;
    server_name         localhost;
    root                www/login;

    # ssl properties
    ssl_certificate      ../../../bin/openssl/certs/cert.pem;
    ssl_certificate_key  ../../../bin/openssl/certs/cert.key;
    ssl_session_timeout  5m;
    ssl_protocols              SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers                HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    log_not_found off;
    charset utf-8;

    access_log  logs/access.log  main;

    # handle files in the root path /www
    location / {
        index  index.php index.html index.htm;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   www;

    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
        try_files      $uri =404;
        fastcgi_index  index.php;
        fastcgi_param  HTTPS on;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

This is the basic WPN-XM configuration (see here) with a modified server to include a listener for 443 as well as the SSL properties.

I can access my page from http://localhost/foo/index.html but when trying to access it from httpS://localhost/foo/index.html I get a 404.

First afternoon with Nginx. Can someone point me to what I’m doing wrong?


My answer:

Your root directives should use absolute paths. It’s not easy to predict where they are going to attempt to read files from with relative paths.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.