0
目前,我在服務器塊中強制HTTPS使用以下配置。現在在nginx上強制使用HTTPS(例外)
if ($scheme != "https") {
rewrite^https://www.domain.tld$request_uri? permanent;
}
我想從這個規則「http://www.domain.tld/some/url」添加一個excaption,只是想不通一個工作配置。
目前,我在服務器塊中強制HTTPS使用以下配置。現在在nginx上強制使用HTTPS(例外)
if ($scheme != "https") {
rewrite^https://www.domain.tld$request_uri? permanent;
}
我想從這個規則「http://www.domain.tld/some/url」添加一個excaption,只是想不通一個工作配置。
Got it!
if ($request_uri != /some/url1) {
set $test A;
}
if ($request_uri != /some/url2) {
set $test "${test}B";
}
if ($scheme = 'http') {
set $test "${test}C";
}
if ($test = ABC) {
rewrite^https://www.domain.tld$request_uri? permanent;
}
使用兩個服務器塊,一個用於安全連接,另一個用於不安全連接。
server {
listen 80;
location/{
return 301 https://$host$request_uri;
}
location /some/url {
...
}
...
include /path/to/common/config;
}
server {
listen 443 ssl;
...
include /path/to/common/config;
}
您可以使用include
指令中常見的配置拉從一個單獨的文件。
閱讀[本文件](https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/)您填寫您的配置文件,'if'塊之前。 –