簡體   English   中英

Nginx重定向到一個路徑(wordpress)

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM