2017-04-24 187 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