Nginx:作为静态资源服务器alias和root的区别

这里记录下Nginx中location中使用alias和root的区别

如使用root

server {
       listen 80;
       server_name 192.168.10.48;       
       location /api/eg/ {
            root   /opt/xcache/nginx/html/;
            autoindex on;
        }
       }

这里实则映射到linux中的/opt/xcache/nginx/html/api/eg/的文件夹中 也就是root对应路径+location
使用alias

server {
       listen 80;
       server_name 192.168.10.48;       
       location /api/eg/ {
            alias   /opt/xcache/nginx/html/;
            autoindex on;
        }
       }

这里实则映射到linux中的/opt/xcache/nginx/html/的文件夹中 也就是访问的只有alias所对应的路径

猜你喜欢

转载自blog.csdn.net/weixin_40763557/article/details/80894671