[英]Nginx redirect for one path (wordpress)
我想在http://example.com/content
上托管一個Wordpress網站。
我的主要站點是example.com上的Meteor站點,前面有nginx。
這是我的nginx配置文件,但是http://example.com/content
只是被重定向到https://example.com/content
而完全忽略了/content
位置塊。 任何想法如何解決這個問題?
# HTTP
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html; # root is irrelevant
index index.html index.htm; # this is also irrelevant
server_name example.com;
location /content/ {
proxy_pass http://123.123.123.123; #wordpress ip
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# redirect non-SSL to SSL
location / {
rewrite ^ https://$server_name$request_uri? permanent;
}
}
如討論的那樣,使用add_header Strict-Transport-Security max-age=15768000;
在example.com
以及您已有許多現有用戶這一事實,意味着在http://example.com
上托管任何內容都是不切實際的。
您正在使用proxy_pass
將WordPress站點托管在現有域的子目錄中,但是WordPress服務器實際上在其他站點上運行。
WordPress服務器不需要,也不能使用example.com
的SSL證書。 將location /content
塊移動到安全服務器:
server {
listen 443 ssl;
server_name example.com;
...
location ^~ /content {
proxy_pass http://123.123.123.123; #wordpress ip
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "";
proxy_set_header Proxy "";
}
}
使用^~
運算符可避免與現有配置產生歧義。 有關詳細信息,請參見此文檔 。
WordPress網站123.123.123.123
必須配置為在https://example.com/content/
下運行,這涉及更改HOME和SITEURL變量。 有關更多信息,請參見此文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.