1 | initial version |
To create an Nginx location block that serves a website on a subpath of a domain, follow the steps below:
Edit the Nginx configuration file using a text editor:
nano /etc/nginx/nginx.conf
Locate the server block for the domain you want to serve the website on a subpath of.
Create a new location block within the server block:
/subpath/ { }
Replace 'subpath' with the name of the subpath you want to use.
Inside the location block, add the root and index directives:
location /subpath/ {
root /var/www/html/subpath;
index index.html index.htm;
}
Replace '/var/www/html/subpath' with the path to the root directory of the website.
Save the changes to the configuration file and test the configuration:
nginx -t
If the configuration file syntax is correct, reload Nginx to apply the changes:
systemctl reload nginx
Verify that the website is accessible at the subpath:
://example.com/subpath/