Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Mapping URL to Different Path In Nginx

    Mapping URL to Different Path In Nginx

    By RahulSeptember 2, 20221 Min Read

    Sometimes we need to map a sub URL to a different directory path in the file system. The Nginx users can achieve this by using the “location” block in the configuration file. The location specifies a regular expression for the URL the browser requests. Under the location code block, we can specify the file system path with the ‘root’ or ‘alias’ option.

    Advertisement

    You may use the alias directive within a location block, like this:

    1
    2
    3
    4
    5
    6
    7
    server {
        server_name www.example.com;
        root /var/www/example.com;
        location /static/ {
            alias /var/content/static/;
        }
    }

    In the above configuration, the main site is configured with the /var/www/example.com directory. But the URL begins with “/static” will be served with “/var/content/static” directory. For example, A URL http://www.example.com/static/file.txt will point to /var/www/static/file.txt file.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    20 Basic Linux Commands for the Beginners (Recommended)

    tail Command in Linux with Examples

    What is a Orphan Process in Unix/Linux

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.