








配置demo:
location xxx {
root yyy
}
浏览器访问 xxx,实际访问的是 yyy/xxx
浏览器访问 xxx/abc.html,实际访问的是 yyy/xxx/abc.html
浏览器访问 xxx/ccc/abc.html,实际访问的是 yyy/xxx/ccc/abc.html
配置demo:
locaiton xxx {
# alias必须以 / 结束,否则无效
alias yyy/
}
浏览器访问 xxx,实际访问的是 yyy
浏览器访问 xxx/abc.html,实际访问的是 yyy/abc.html
浏览器访问 xxx/ccc/abc.html,实际访问的是 yyy/ccc/abc.html
nginx的目录结构如下:
nginx/
-html/
-index.html
-logs/
- access.log
-conf/
-nginx.conf
1) 这种配置,http://localhost:8086/access.log,能看到 nginx/logs/access.log,但就别指望能访问 html目录下的文档了
server {
listen 8086;
server_name localhost;
location / {
root logs;
}
}
2) 这种配置,访问 http://localhost:8086/log/access.log,能看到 nginx/logs/access.log;
访问 http://localhost:8086/, 能看到 nginx/html/index.html
server {
listen 8086;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
# 配置成 location /log/ 或 location /log 都可以
location /log/ {
# 不能写成logs, 必须已 / 结束
alias logs/;
# 以下配置没用也可以,只是方便你输入 localhost:8086/log/ 后能,看到nginx/logs/目录下的所有文件
autoindex on;
}
}
3) 这种配置,访问 http://localhost:8086/logs/access.log,能看到 nginx/logs/access.log;
访问 http://localhost:8086/, 能看到 nginx/html/index.html
server {
listen 8086;
server_name localhost;
4) 错误的配置
server {
listen 8086;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
节选:https://www.cnblogs.com/zhang... 这段话:
root属性指定的值是要加入到最终路径的,所以访问的位置变成了 root的值/locaiton的值。而我不想把访问的URI加入到路径中。所以就需要使用alias属性,其会抛弃URI,直接访问alias指定的位置
参考:
https://www.cnblogs.com/zhang...
https://www.cnblogs.com/kevin...
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。