我试图使用nginx作为反向代理( 服务器A )到我的WordPress服务器( 服务器B )托pipe使用Nginx。 我正在试图设置我的url在一个子目录格式,如example.com/blog
它有点作品,但有一些问题。
服务器A具有LetsEncrypt SSL证书,因此它会在所有路由上强制使用https 。 这是一个问题,因为我的wordpress应用程序正在http上加载.js&.css文件。
成功login后,不是redirect到example.com/blog/wp-admin ,而是转到example.com/wp-admin
我的服务器一个 nginx conf文件,包含相应的位置块,
location /blog { rewrite ^/blog/(.*)$ /$1 break; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_pass http://ip-address-for-server-b; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }
我的服务器B的 nginx conf文件
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; server_name localhost; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; allow all; } location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ { expires max; log_not_found off; } location / { # try_files $uri $uri/ =404; try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }
另外在我的wp-config.php ,我添加了这些行
define( 'WP_SITEURL', 'https://example.com/blog' ); define( 'WP_HOME', 'https://example.com/blog' );