Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create an Nginx location block that serves a website on a subpath of a domain, follow the steps below:

  1. Edit the Nginx configuration file using a text editor:

    nano /etc/nginx/nginx.conf

  2. Locate the server block for the domain you want to serve the website on a subpath of.

  3. Create a new location block within the server block:

    /subpath/ { }

    Replace 'subpath' with the name of the subpath you want to use.

  4. 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.

  5. Save the changes to the configuration file and test the configuration:

    nginx -t

  6. If the configuration file syntax is correct, reload Nginx to apply the changes:

    systemctl reload nginx

  7. Verify that the website is accessible at the subpath:

    ://example.com/subpath/