我终于得到了一个适用于 WordPress 博客的 NGINX 反向代理!
我的设置是由 NGINX 在端口 8080 上提供服务的 WordPress 站点和在子目录“blog”上提供 WordPress 博客的默认站点(在端口 80 上)。 (例如。http://www.example.com/blog).
在我的“默认站点”NGINX 配置中,我定义了以下反向代理位置:
location ^~ /blog/ {
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_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;
}
在 wp-config.php 中我做了以下修改:
/** set the site URL */
define('WP_HOME','http://www.example.com/blog');
define('WP_SITEURL','http://www.example.com/blog');
/** Fix to get the dashboard working with the reverse proxy.*/
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/", $_SERVER['REQUEST_URI']);
为了完整起见,以下是 WordPress 博客的基本 NGINX 配置:
server {
listen 8080;
listen [::]:8080;
server_name example.com;
root /var/www/blog;
<...>
location / {
index index.php
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_index index.php;
}
}
版本:
- 乌班图18.04
- NGINX 版本 1.4
- PHP 7.2
- WordPress 4.8.5