我在 nginx 代理后面的 apache 上有一个 wordpress 站点。 我已经配置了 SSL,但现在我无法预览草稿帖子,它们最终会无限重定向到相同的 url。
在我们的 wp-config 中我们有:
define( 'FORCE_SSL_LOGIN', true );
define( 'FORCE_SSL_ADMIN', true );
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';
我们有 .htaccess 用于 apache 根目录:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/Site/
RewriteCond %{REQUEST_URI} !^/phpMyAdmin/
RewriteRule ^(.*)$ /Site/$1
RewriteCond %{REQUEST_URI} !^/phpMyAdmin/
RewriteRule ^(/)?$ /Site/index.php [L]
我们有 .htaccess 用于站点文件夹:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
如果我在 http 中访问帖子预览,它会起作用: http://my.domain/?post_type=portfolio&p=3405&preview=true
但是对于 https,它会一遍又一遍地重定向 (301) 到相同的 url: https://my.domain/?post_type=portfolio&p=3405&preview=true
我在 wordpress index.php 中添加了一个输出缓冲区,所以我可以在日志中看到,当访问安全链接时,它会生成后预览 html,因此重定向一定发生在返回的路上,之后PHP 引擎生成了后期预览。
对于安全链接,在我看到的 apache 访问日志中,所以我认为问题不是 nginx 引起的:
"GET/?post_type=portfolio&p=3405&preview=true HTTP/1.0"301
我们使用永久链接,因此在 http 和 https 中预览发布的帖子都没有任何问题。 有什么想法吗?
谢谢, 里尔
最佳答案
所提供的代码正在检查 X-Forwarded-Proto header 是否设置为 https。您需要确保 nginx 在转发中添加它 - 类似于以下内容:
location / {
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://127.0.0.1:10554;
}
关于wordpress - 使用 SSL 的无限重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22147839/