【问题标题】:infinite redirect loop with SSL使用 SSL 的无限重定向循环
【发布时间】:2014-03-03 13:17:25
【问题描述】:

我在 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中添加了一个输出缓冲区,所以我可以在日志中看到,当访问安全链接时,它会生成post preview html,所以重定向一定是在返回的路上发生的,之后php 引擎生成了帖子预览。

对于安全链接,在我看到的 apache 访问日志中,所以我认为不是 nginx 导致了问题:

“GET /?post_type=portfolio&p=3405&preview=true HTTP/1.0”301

我们使用永久链接,因此在 http 和 https 中预览发布的帖子都没有任何问题。 有什么想法吗?

谢谢, 利奥

【问题讨论】:

  • 我想我有一个方向——通过禁用 Better WP Security 插件,我成功地用 ssl 预览了草稿(尽管它有一些混合内容)。所以我会去插件论坛看看类似的问题。

标签: wordpress apache .htaccess redirect ssl


【解决方案1】:

提供的代码检查 X-Forward-Proto 标头是否设置为 https。您需要确保 nginx 将其添加到转发中 - 如下所示:

location / {
            proxy_set_header X-Forwarded-Proto https;
            proxy_pass http://127.0.0.1:10554;
}

【讨论】:

    猜你喜欢
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 2017-04-10
    • 2015-05-23
    • 2016-02-02
    • 2013-01-25
    相关资源
    最近更新 更多