gpt4 book ai didi

php - NGINX + Wordpress 给出 ERR_TOO_MANY_REDIRECTS

转载 作者:行者123 更新时间:2023-12-02 03:55:04 32 4
gpt4 key购买 nike

我一直在尝试使用 NGINX 作为网络服务器来托管一个简单的 Wordpress 博客。该博客作为 domain_name.com/blog 下的子目录托管。

主博客正确打开。但是当尝试打开 domain_name.com/blog/wp-admin 下的 wp-admin 时,我的浏览器显示 ERR_TOO_MANY_REDIRECTS。

我不确定这是我的 NGINX 配置还是 wordpress 配置的问题。以下是我的 NGINX 服务器 block :

server {
listen 80;
server_name <domain_name.com>;
root /var/www/html;
index index.php;

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

location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

Wordpress 安装在/var/www/html/blog 目录下。并且数据库中“siteurl”和“home”wp_options 的值都指向 domain_name.com/blog。

解决这个问题的好方法是什么?

可能有用的附加说明:当我尝试访问 wp-content 目录下的静态文件时,它们打开时没有任何问题。那里没有重定向错误。

最佳答案

每当访问 wp-admin 时,WordPress 通常会将 http session 重定向到 https。这可以使用 wp-config.php 中的 FORCE_SSL_LOGINFORCE_SSL_ADMIN 设置来控制。

当反向代理终止 SSL 时,必须将原始连接通过 https 的事实传达给 WordPress,以避免重定向循环。

您的反向代理应该设置诸如 X-Forwarded-Proto 之类的 header 。

您需要更改您的 nginx 配置,以便为 WordPress 正确设置 HTTPS 标志。

例如:

map $http_x_forwarded_proto $https_flag {
default off;
https on;
}

server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php;

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

location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;

fastcgi_param HTTPS $https_flag;
fastcgi_pass php;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

关于php - NGINX + Wordpress 给出 ERR_TOO_MANY_REDIRECTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44242267/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com