Duncan Wither

Home Notes Github LinkedIn

Nginx

File Locations

Web files are located here:

/var/www/html/

But this can be adjusted in the config.

Global config file is:

/etc/nginx/nginx.conf

This then looks for files in:

/etc/nginx/sites-enabled/

Best practice is to keep the actual config files in:

/etc/nginx/sites-avalible/

And then link them (using ln -s) to the enabled folder. Nginx will read this properly.

Remove the .html extension

To remove the .html from websites add the following lines:

location / {
    if ($request_uri ~ ^/(.*)\.html(\?|$)) {
        return 302 /$1;
    }
    try_files $uri $uri.html $uri/ =404;
}

Courtesy of stack exchange.

Set 404 Page

Add this to you’re config.

error_page 404 /custom_404.html;
        location = /custom_404.html {
                root /usr/share/nginx/html;
                internal;
        }

Thank you digital ocean

Generator

TBH after a bunch of faffing with nginx recently I ended up starting from scratch using digital oceans tool. It’s very quick and easy. Would recommend.