Ask Your Question
3

What is the process for creating an Nginx location block that serves a website on a subpath of a domain?

asked 2023-06-07 06:46:05 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-07 07:01:02 +0000

nofretete gravatar image

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/

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-07 06:46:05 +0000

Seen: 12 times

Last updated: Jun 07 '23