我有两个域的服务器
- 服务器托管mywebsite.com和
- 服务器B托管blog.mywebsite.com(博客WordPress)。
我的目标是为我的博客提供一个无缝的URL:http://mywebsite.com/test23带有服务器的内容b。
我的第一个重定向正在工作(位置/test23)。我可以获取我的主页并获取其他页面,但是我无法连接到我的WP管理员。我在mywebsite.com/test23/wp-login.php。
上获得404服务器a nginx conf文件
index index.php index.html index.htm;
server_name mywebsite.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_read_timeout 1000;
}
location /test23 {
rewrite ^/test23(.*) /$1 break;
proxy_pass http://blog.mywebsite.com/;
}
location /test23/wp-admin {
rewrite ^/test23/wp-admin(.*) /$1 break;
proxy_pass http://blog.mywebsite.com/wp-admin;
}
我想我需要管理WP-Admin文件夹的排除?我失去了:d
因为您代理"/test23"路径,并且使用重写规则使用ADRESS绑定所有内容,而您不需要第二个位置块。
尝试使用以下方式:
location /test23 {
rewrite ^/test23(/.*)$ /$1 break;
proxy_pass http://blog.mywebsite.com/;
}
如果您没有设置代理规则,则此块可能看起来像:
location /test23 {
rewrite ^/test23(/.*)$ /$1 break;
proxy_pass http://blog.mywebsite.com/;
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 https;
proxy_redirect off;
}
您应该在重写中" test23"之后使用后斜线。在第一种情况下,它有效,因为请求中没有任何之后/test23。
在第二个请求中,由于位置块的位置很重要,因此它被混合在一起。因此,它被第一个规则重写,这会导致错误而没有后斜线。