在作一个项目时要用到nginx,原本配置nginx是一件不太难的事情,结果怎么都访问不了 (404都是泪:( )。html
server {
...
location / {
// 就是这里,alias 与 root配置,后面要 / 结尾,并且windows下也要使用 /,不然报错
alias D:/xc-nginx/nginx-1.16.1/html/xc-ui-pc-static-portal/;
index index.html index.htm;
}
...复制代码
但刚开始源文件添加的是 root,因而想探究一下root与alias区别nginx
server {
...
location / {
root D:/xc-nginx/nginx-1.16.1/html/xc-ui-pc-static-portal;
index index.html index.htm;
}
...复制代码
root和alias都是nginx指定文件路径的方式web
[root]
语法:root path
默认值:root html
配置段:http、server、location、if
windows
[alias]
语法:alias path
配置段:locationbash
区别在于nginx如何解释location后面的uri
root的处理结果是:root路径+location路径
alias的处理结果是:使用alias路径替换location路径
服务器
root实例:ui
1
2
3
|
location /ying/ {
root /www/root/html/;
}
|
若是一个请求的URI是/ying/a.html时,web服务器将会返回服务器上的/www/root/html/ying/a.html的文件。spa
alias实例:code
1
2
3
|
location /ying/ {
alias /www/root/html/new_t/;
}
|
若是一个请求的URI是/ying/a.html时,web服务器将会返回服务器上的/www/root/html/new_t/a.html的文件。cdn
遇到本身不熟悉的技术点屡次折腾无果后应该及时查阅配置,这样解决问题效率会更高一些。