nginx配置location时,不能完全匹配路径

PHP编程者 2015-11-12 06:39:40
我有个域名 www.xxx.com
目的:正常访问时指向目录A(/home/a),当url中含路径/v3/时指向目录B(/home/b)
但下面的配置,当我访问 www.xxx.com/v3/时指向目录B,但访问www.xxx.com/v3/home时却指向了目录A
问题出在哪呢?
配置如下:

server {
listen 80;
server_name www.xxx.com;

access_log /var/log/nginx/qhq/qhq_bool_tmp_access.log main;
error_log /var/log/nginx/qhq/qhq_bool_tmp_error.log debug;

set $web_root /home/a;

location ^~ /v3/ {
alias /home/b/;
index index.html index.htm index.php;

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}

location / {
root $web_root;
index index.html index.htm index.php;
if (!-f $request_filename) {
rewrite (.*) /index.php last;
}
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root $web_root;
}


location ~ \.php$ {
root $web_root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $web_root/$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\. {
deny all;
access_log off;
log_not_found off;
}

}
...全文
843 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
PHP编程者 2015-12-15
  • 打赏
  • 举报
回复
好像可以嵌套
孟子E章 2015-11-14
  • 打赏
  • 举报
回复
我测试了是可以的。 location ^~ /v3/ { alias /home/b/; index index.html index.htm index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; } } location 可以嵌套?

5,655

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧