时间:2021-07-01 10:21:17 帮助过:14人阅读
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /hsc {
root /home/hsc/nginx;
index index.html;
}
location / {
root /home/hsc/nginx/hsc;
index index.html index.htm;
}
}如上一个简单server配置,在浏览器中输入127.0.0.1 和127.0.0.1/hsc其请求的结果是一样都是/home/hsc/nginx/hsc 目录下的index.html解释下:127.0.0.1 会匹配到 location / 然后 root(表示根目录) 为/home/hsc/nginx/hsc 然后nginx 再去找/后面的内容这里为空,所以就找根目录下的内容。
27.0.0.1/hsc 会匹配到 llocation /hsc 然后 root(表示根目录) 为/home/hsc/nginx 然后nginx 再去找/后面的内容这里为hsc这个目录,所以就会切换到/home/hsc/nginx/hsc目录下。
以上就介绍了Nginx location 配置心得,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。