[英]nginx same location but with different directives
尝试看是否可行。
我们有一个应用程序和一个WordPress安装。
是否可以在同一文件夹中但在不同情况下使用2个位置。 例..
http://domain.com/subfolder/-显示APP http://domain.com/subfolder/anything-显示WP永久链接
现在,我们有
http://domain.com/subfolder (不带/)显示了该应用
http://domain.com/subfolder/ (不带/)显示WP。
的确可以,但是如果URL包含在子文件夹/ *之后的文本,它将仅显示WP。
当前的Nginx conf:
location ^~ /knowledge {
root /opt/domain.com/public/;
try_files $uri @backend;
}
location /knowledge/ {
index index.php index.html index.htm;
root /opt;
include /etc/nginx/php-wpsc.conf;
try_files $uri $uri/ /knowledge/index.php?q=$uri&$args;
}
显然,保留WordPress的location /knowledge/
块是有意义的,因为它与大多数情况匹配,只有一种情况需要覆盖。
通过使用优先级更高的位置块,可以从该位置块中删除特定的URI。 有关详细信息,请参见此文档 。
一种可能是精确匹配位置块:
location = /knowledge/ {
rewrite ^ /knowledge last;
}
或者可能将现有location ^~ /knowledge
块从前缀位置更改为正则表达式位置,从而使尾部/
可选。
location ~ ^/knowledge/? { ... }
请注意,这会更改此位置块的评估顺序,因此可能需要考虑副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.