Adding location to Nginx server configuration

Author: Al-mamun Sarkar Date: 2020-04-14 08:19:28

Adding locations to Nginx server configuration. The following command shows how to add locations on nginx web server virtual host configurations.  

 

Edit artofcse.local.conf and add the following codes:

server {
        listen 80 default_server;
        server_name artofcse.local www.artofcse.local;
        index index.html index.htm index.php;
        root /var/www/artofcse.com;


        location / {
                try_files $uri $uri/ =404;
        }

        location /images {
                autoindex on;
        }

        error_page 404 /404.html;
        location = /404.html {
                internal;
        }
}

 

Create 404.html page:

echo "404 page not found" > /var/www/artofcse.com/404.html

 

Test Nginx configuration:

nginx -t

 

Restart Nginx Server:

systemctl reload nginx