2017-04-24 183 views
0

我想主辦一個Wordpress站點http://example.com/contentNginx重定向一個路徑(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; 
    } 
} 
+0

你的位置塊是'/ content /'而不是'/ content',正如問題所暗示的那樣。另外,您的安全網站是否使用HSTS標頭? –

+0

我用/ content試過它,它也沒有工作。真的是我想要它的內容/ *去wp網站上的/ * –

+0

我不知道什麼是hsts。主站點使用https,而wp不支持 –

回答

0

如前所述,在example.com使用add_header Strict-Transport-Security max-age=15768000;和你有一些現有用戶的事實,意味着在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    ""; 
    } 
} 

使用^~操作,以避免與現有配置的任何歧義。詳情請參閱this document

123.123.123.123上的WordPress網站必須配置爲在https://example.com/content/下運行,其中涉及更改HOME和SITEURL變量。有關更多信息,請參閱this document