请教关于网站根目录的Location匹配问题
来源:5-4 Nginx常见问题_多个location匹配的优先级2
			ch3rish
2018-01-20
服务器上文件目录如下
root@xxx:/var/www/html# tree . ├── admin ├── home └── weixin
home下是网站主页的项目
admin 是管理平台,通过www.domain.cn/admin/访问
weixin 是微信方面的,通过www.domain.cn/weixin/访问
nginx配置是
server {
        listen 80;
        server_name domain.cn;
        root /var/www/html/;
        index index.html;
  location /weixin/ {
        try_files $uri /weixin/index.html;
   }
  location /admin/ {
        root /var/www/html/;
        index index.html;
   }
  location / {
        root /var/www/html/home/;
        index index.html;
   }但是这样感觉不够优雅,因为如果要添加新的项目,有一个就要单独设置一个location
我希望是能把home的那条location单独拎出来,其他的项目,因为是静态文件,走server的root位置,而不需要另外单独配置location,这样如果要添加新的项目,只需要放到/var/www/html/目录下即可。
server {
        listen 80;
        server_name domain.cn;
        root /var/www/html/;
        index index.html;
  location /weixin/ {
        try_files $uri /weixin/index.html;
   }
  location / {
        root /var/www/html/home/;
        index index.html;
   }但是这样会导致访问www.domain.cn/admin/ 404
我想应该是
location /
这里匹配的问题,该怎么匹配根目录呢 谢谢
写回答
	1回答
- 
				
						Jeson
2018-01-21
很好的问题描述,我觉得导致你404的原因是因为在配置location /下root路径为/var/www/html/home,所以/admin的路径请求在/var/www/html/home/admin是找不到的。因为admin的目录仍然放在了/var/www/html这一级下。
042018-01-24 
相似问题