rewrite - What is the specific use of nginx alias?
黄舟
黄舟 2017-05-16 17:15:38
0
1
494

I’ve been looking at nginx recently, but I’m not sure what the specific use of alias is. Both root and rewrite can achieve it, why use alias?

root /data/mydomain/main/web/;
location ~* ^/app(|/)$ {
        #alias /data/mydomain/main/public/app/;
        rewrite  ^/app(|/)$ /public/app/ last;
        expires 30s;
}

In the above configuration, rewrite takes effect and meets my expectations. But there is a problem with alias.

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
Ty80

This is a matter of your own understanding. First of all, rewrite has nothing to do with root and alias.
rewrite is for http requests. The path in it is the address in the URL, which is the conversion between addresses.
The root and alias are the settings of the system file path.
The root in the area is used to set the root directory, and alias is used to reset the directory of the current file.

location /img/ {
    alias /var/www/image/;
}
#若按照上述配置的话,则访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件
location /img/ {
    root /var/www/image;
}
#若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件。]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template