[英]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.