wordpress - 固定链接问题——在同样是 NGINX 的反向代理后面的 NGINX 上运行 Wordpress

标签 wordpress nginx

我有 2 个服务器实例,它们都运行 NGINX。

  1. NGINX-A,它是反向代理。它根据其配置中的位置 block 将流量转发到不同的内部服务器
  2. NGINX-B 是一个服务器实例,我们所有的 PHP 网络应用程序都部署在上面。
  3. 其他服务器实例

因此 NGINX-A 接收所有传入流量,将其重新路由到适当的服务器。 NGINX-B 是在 NGINX 而不是 Apache 上运行的传统 Wordpress 托管。


我正在尝试使 postname 永久链接 起作用,但没有成功。

我当前的目录结构:

/appl/wordpress/myblog == symbolic link ==> /usr/share/nginx/html/subdir/myblog

这是我在安装了 Wordpress 的 NGINX-B 服务器上的当前配置。

location /subdir/myblog/ {
     try_files $uri $uri/  /subdir/myblog/index.php?$args;
}

通过 http://NGINX_B-ip_address/subdir/myblog 访问它postname permalinksplain permalinks 都有效。我确实必须像下面这样更新 wp-config。

define('WP_HOME', 'NGINX_B-ip_address')
define('WP_SITEURL','NGINX_B-ip_address');

现在,我有另一个充当反向代理的 nginx 服务器 NGINX-A。

location /{
    proxy_pass http://NGINX_B-internal_ip_address;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    #for wordpress
    proxy_set_header X-Forwarded-Proto $scheme;
}

我还必须用新主机名更新 wp-config.php

define('WP_HOME', 'http://NGINX-A-hostname/myblog')
define('WP_SITEURL','http://NGINX-A-hostname/myblog');

它使用plain permalinks 工作,我可以毫无问题地访问 wp-admin。我还可以更改永久链接策略。

如果我不使用plain permalinks,整个事情就会崩溃并不断出现 404 错误。

  1. http://NGINX-A-hostname/myblog - 作品
  2. http://NGINX-A-hostname/myblog/wp-admin - 完全有效
  3. http://NGINX-A-hostname/myblog/postname - 失败 | 404
  4. http://NGINX-A-hostname/myblog/?p=postname - 完全有效

就好像 NGINX 反向代理将请求转发为目录而不是参数。有什么建议吗?谢谢!

最佳答案

好的,我通过将其应用于 NGINX-B 服务器成功解决了我的问题

location /myblog {
        root /usr/share/nginx/html/subdir;
        try_files $uri $uri/  /myblog/index.php?$args;
        location  ~ \.php$  {
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_index   index.php;
              fastcgi_pass unix:/var/run/php5-fpm.sock;
              include /etc/nginx/fastcgi_params;
              fastcgi_param   SCRIPT_FILENAME $request_filename;
        }
}

我以前的配置是这样的,但没有用。

location /subdir/myblog/ {
     try_files $uri $uri/  /subdir/myblog/index.php?$args;
}

这也没有用。不要在根条目。 myblog 部分不应存在,myblog 应包含在 try_files 中。

location /myblog {
root /usr/share/nginx/html/subdir/myblog;
    try_files $uri $uri/  /index.php?$args;
    location  ~ \.php$  {
               fastcgi_split_path_info ^(.+\.php)(/.+)$;
               fastcgi_index   index.php;
               fastcgi_pass unix:/var/run/php5-fpm.sock;
               include /etc/nginx/fastcgi_params;
               fastcgi_param   SCRIPT_FILENAME $request_filename;
       }
}

关于wordpress - 固定链接问题——在同样是 NGINX 的反向代理后面的 NGINX 上运行 Wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42197932/

相关文章:

css - wordpress中的自定义样式表标签

deployment - 使用 Capistrano 部署时如何升级 Wordpress 和插件?

wordpress 显示所有自定义分类法及其相关帖子

python - 同时将 nginx 设置为 apache 和 gunicorn 的代理

php - 带有 Nginx 的子目录上的 Wordpress 使用无输入文件错误的代理通行证

Wordpress:元描述,嵌入 Youtube

php - php 上的超链接

docker - docker中的nginx无法与localhost对话

css - Nginx 不会提供静态文件

linux - 在 debian 上重建包和包管理器