Nginx配置不生效的问题解决
先看正确的nginx配置文件的主要部分:
注意 ^~ 的部分,这样就根目录,a路径,还有b路径都能生效了。server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location ^~/a { alias /home/www/a; //此处为a的路径 index index.html; } location ^~/b { alias /home/www/b; //此处为a的路径 index index.html; } }
如果这样写是不生效的:server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /a { // 这里不生效 alias /home/www/a; //此处为a的路径 index index.html; } location /b { // 这里不生效 alias /home/www/b; //此处为a的路径 index index.html; } }
希望帮助到有需要的小伙伴。