2

First off, first time nginx user. So, I'm still learning the differences from Apache and nginx.

I have a stock install of nginx. (apt-get install nginx-full) I modified the default configuration found at '/etc/nginx/sites-enabled/default' for my setup. However, error pages just don't work. My docroot is /server/www, and my error pages are located within the directory /server/errors/. Below is my config.

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /server/www;
    index index.html;

    server_name website.com;

    location / {
        try_files $uri $uri/ /index.html;
    }

    error_page 403 404 405 /40x.html;
    location /40x.html {
        root /server/errors;
        internal;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /server/errors;
        internal;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

All pages that should generate a 403 or 404 page, just load the index.html file. I believe the something is probably happening with 500 errors, however, that's a bit harder to generate.

Also, if it's relevant, I moved the error pages above docroot, but they weren't working before that. I made that move as the 'internal' flag didn't appear to make the pages internal as the documentation claimed, as I could still access them directly.

Any advise/help you could give would be great!

3
  • I have to ask, did you reload nginx when you changed the settings? Commented Mar 4, 2014 at 5:33
  • wiki.nginx.org/HttpCoreModule - Please read the 'order' section. Commented Mar 4, 2014 at 11:47
  • Yes, I did restart nginx after each change to the configuration. Commented Mar 4, 2014 at 19:12

1 Answer 1

2

The error issue was related to the location / having an end value of /index.html. Essentially, nginx was first trying the uri as a file, then as a directory, and then reverting to index.html. Instead I wanted it to return a 404. So I changed it to the below and now it works.

location / {
    try_files $uri $uri/ =404;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.