Nginx set alias to implement the virtual directory alias and root usage difference

Source: Internet
Author: User

Nginx does not seem to have a virtual directory, because it is completely based on the directory to design and work. If you want to give nginx a virtual directory, it is only the alias tag comparison "like", simply say the alias tag and root tag differences. The basic difference: the directory specified by alias is accurate, root is the parent directory of the specified directory, and the parent directory will contain the directory with the same name as the location specified. Also, according to the previous article, the rewrite break cannot be used in a directory block that uses the alias tag.

Don't understand, look under configuration:

location/abc/{
alias/home/html/abc/;
}

In this configuration, the http://test/abc/a.html is specified as/home/html/abc/a.html. This configuration can also be changed to

location/abc/{
root/home/html/;
}

In this way, Nginx will find the/home/html/directory under the ABC directory, the results are the same. However, if I change the alias configuration to:

location/abc/{
alias/home/html/def/;
}

Then Nginx will take data from/home/html/def/, this configuration is not directly using the root configuration, if not to configure, only under the/home/html/to establish a DEF->ABC soft link (shortcut). In general, it is a good practice to configure alias in Location/other by configuring root in Location/. As for the difference between alias and Root, I guess it hasn't been said completely, if you find a singular problem in the configuration, you might want to change the two for a try.

Settings for Nginx alias

Nginx also has an alias function like Apache, in the form of:

Location ~/alias {
Root/home/www/default;
Index index.php;
}

But nginx in the processing of PHP script, need to pass to fastcgi to handle, so more than Apache alias settings, the following we set the phpMyAdmin alias as an example:

Location ~ ^/phpmyadmin.+.php$ {
Root/home/www/default;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
Location ~/phpmyadmin {
Root/home/www/default;
Index index.php;
}

Nginx set alias to implement the virtual directory alias and root usage difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.