服务器上文件目录如下
1 2 3 4 5 | root@xxx: /var/www/html # tree . ├── admin ├── home └── weixin |
home下是网站主页的项目
admin 是管理平台,通过www.domain.cn/admin/访问
weixin 是微信方面的,通过www.domain.cn/weixin/访问
nginx配置是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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/目录下即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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
我想应该是
1 | location / |
这里匹配的问题,该怎么匹配根目录呢 谢谢