Wordpress(WooCommerce?)强制 https(当它不应该时)
Wordpress (WooCommerce?) forces https (when it shouldn't)
我在公司接管的 WooCommerce 安装中遇到了一个奇怪的问题。它不是我们建造的,不幸的是它建造得很糟糕,所以我不太确定里面到底发生了什么。
它突然开始 "force" https 连接,但据我所知,无论是代码还是管理员,都没有任何变化。我们在服务器上 运行 Git 并且工作树中没有任何变化,我在上传文件夹中搜索可疑文件但没有结果。不太可能是某种恶意软件。该站点未设置 https/ssl,因此这当然会触发超时。
我检查了数据库,home_url
和 site_url
都设置为 "http://..."。 WooCommerce 选项 "force ssl" 设置为 false。此外,我们是 运行 插件 "Better WP Security/iThemes Security",它也提供了一个 "force ssl" 选项,但那个选项也被设置为 false。
我尝试在 wp-config.php 中将常量 FORCE_SSL_ADMIN
和 FORCE_SSL_LOGIN
都设置为 false - 仍然没有成功。我也尝试使用 .htaccess 重写规则,但这也没有帮助。
好像跟一个请求有关header; HTTPS: 1
(使用 $ curl -I -H"HTTPS: 1" http://...
测试)。当那个设置为 0
时,这不会发生。不过Chrome好像是默认发送的,其他浏览器不是这样的。我尝试清除 cookies/data 等。问题也出现在我同事的浏览器中(她以前从未访问过该站点)。托管公司表示这与服务器配置无关。
有没有人以前经历过这种情况,或者知道它可能与什么有关?
更新:
运行 curl -I -H"HTTPS: 1" http://www.example.com/wp-admin/
几乎可以证实这与 Wordpress 有关。 cookie 由 WPML 设置,表示 Wordpress 已初始化。检查 Location:
header:
HTTP/1.1 302 Moved Temporarily
Server: Apache
X-Powered-By: PHP/5.6.11
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Set-Cookie: _icl_current_admin_language=sv; expires=Wed, 22-Jul-2015 16:06:25 GMT; Max-Age=7200; path=/wp-admin/
Set-Cookie: _icl_current_language=sv; expires=Thu, 23-Jul-2015 14:06:25 GMT; Max-Age=86400; path=/
Set-Cookie: PHPSESSID=xxx; path=/
Location: https://www.example.com/wp-login.php?redirect_to=https%3A%2F%2Fwww.example.com%2Fwp-admin%2F&reauth=1
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
Date: Wed, 22 Jul 2015 14:06:26 GMT
X-Varnish: nnn
Age: 0
Via: 1.1 varnish
Connection: keep-alive
我通过关闭 WooCommerce 设置中的强制 SSL 设置解决了这个问题,然后通过作为此插件的一部分提供的复选框(在“编辑页面”屏幕上)明确设置这 3 个 WooCommerce 页面以使用 SSL。
The pages that needing SSL according to WooCommerce are:
1. Checkout
2. Checkout -> Pay
3. My Account
也试试,
<?php
if (is_ssl()) {
//action to take for page using SSL
}
?>
Returns 如果页面使用 SSL(检查是否为 HTTPS 或端口 443)则为真。
将 Woocommerce 更新到 2.3.13 为我修复了它
@Zertuk 的解决方案是正确的:升级到最新的 WooCommerce 应该可以解决这个问题,因为 change that @Zertuk has linked.
提供更多详细信息:Chrome 已实施来自万维网联盟 (W3C) 的 升级不安全请求 规范。该规范的 Section 3.2.1 是 HTTPS HTTP 请求 Header 字段,它声明
3.2.1. The HTTPS HTTP Request Header Field
The HTTPS HTTP request header field sends a signal to the server
expressing the client’s preference for an encrypted and authenticated
response, and that it can successfully handle the
upgrade-insecure-requests directive in order to make that preference
as seamless as possible to provide.
This preference is represented by the following ANBF:
"HTTPS:" *WSP "1" *WSP
如果设置了 HTTPS: 1
header,WooCommerce 2.3.13 之前的 is_ssl()
函数会错误地重写响应中的所有 URL。
升级到最新版本的 WooCommerce(当前为 2.3.13)修复了该错误。
柯比是对的。
我通过修改 Wordpress 核心函数 is_ssl() 进行了快速修复。
我在函数开头return false 因为我的一些网站没有SSL。
不建议因为更新而修改Wordpress的核心,但我可以控制。
我在公司接管的 WooCommerce 安装中遇到了一个奇怪的问题。它不是我们建造的,不幸的是它建造得很糟糕,所以我不太确定里面到底发生了什么。
它突然开始 "force" https 连接,但据我所知,无论是代码还是管理员,都没有任何变化。我们在服务器上 运行 Git 并且工作树中没有任何变化,我在上传文件夹中搜索可疑文件但没有结果。不太可能是某种恶意软件。该站点未设置 https/ssl,因此这当然会触发超时。
我检查了数据库,home_url
和 site_url
都设置为 "http://..."。 WooCommerce 选项 "force ssl" 设置为 false。此外,我们是 运行 插件 "Better WP Security/iThemes Security",它也提供了一个 "force ssl" 选项,但那个选项也被设置为 false。
我尝试在 wp-config.php 中将常量 FORCE_SSL_ADMIN
和 FORCE_SSL_LOGIN
都设置为 false - 仍然没有成功。我也尝试使用 .htaccess 重写规则,但这也没有帮助。
好像跟一个请求有关header; HTTPS: 1
(使用 $ curl -I -H"HTTPS: 1" http://...
测试)。当那个设置为 0
时,这不会发生。不过Chrome好像是默认发送的,其他浏览器不是这样的。我尝试清除 cookies/data 等。问题也出现在我同事的浏览器中(她以前从未访问过该站点)。托管公司表示这与服务器配置无关。
有没有人以前经历过这种情况,或者知道它可能与什么有关?
更新:
运行 curl -I -H"HTTPS: 1" http://www.example.com/wp-admin/
几乎可以证实这与 Wordpress 有关。 cookie 由 WPML 设置,表示 Wordpress 已初始化。检查 Location:
header:
HTTP/1.1 302 Moved Temporarily
Server: Apache
X-Powered-By: PHP/5.6.11
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Set-Cookie: _icl_current_admin_language=sv; expires=Wed, 22-Jul-2015 16:06:25 GMT; Max-Age=7200; path=/wp-admin/
Set-Cookie: _icl_current_language=sv; expires=Thu, 23-Jul-2015 14:06:25 GMT; Max-Age=86400; path=/
Set-Cookie: PHPSESSID=xxx; path=/
Location: https://www.example.com/wp-login.php?redirect_to=https%3A%2F%2Fwww.example.com%2Fwp-admin%2F&reauth=1
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
Date: Wed, 22 Jul 2015 14:06:26 GMT
X-Varnish: nnn
Age: 0
Via: 1.1 varnish
Connection: keep-alive
我通过关闭 WooCommerce 设置中的强制 SSL 设置解决了这个问题,然后通过作为此插件的一部分提供的复选框(在“编辑页面”屏幕上)明确设置这 3 个 WooCommerce 页面以使用 SSL。
The pages that needing SSL according to WooCommerce are:
1. Checkout
2. Checkout -> Pay
3. My Account
也试试,
<?php
if (is_ssl()) {
//action to take for page using SSL
}
?>
Returns 如果页面使用 SSL(检查是否为 HTTPS 或端口 443)则为真。
将 Woocommerce 更新到 2.3.13 为我修复了它
@Zertuk 的解决方案是正确的:升级到最新的 WooCommerce 应该可以解决这个问题,因为 change that @Zertuk has linked.
提供更多详细信息:Chrome 已实施来自万维网联盟 (W3C) 的 升级不安全请求 规范。该规范的 Section 3.2.1 是 HTTPS HTTP 请求 Header 字段,它声明
3.2.1. The HTTPS HTTP Request Header Field
The HTTPS HTTP request header field sends a signal to the server expressing the client’s preference for an encrypted and authenticated response, and that it can successfully handle the upgrade-insecure-requests directive in order to make that preference as seamless as possible to provide.
This preference is represented by the following ANBF:
"HTTPS:" *WSP "1" *WSP
如果设置了 HTTPS: 1
header,WooCommerce 2.3.13 之前的 is_ssl()
函数会错误地重写响应中的所有 URL。
升级到最新版本的 WooCommerce(当前为 2.3.13)修复了该错误。
柯比是对的。
我通过修改 Wordpress 核心函数 is_ssl() 进行了快速修复。
我在函数开头return false 因为我的一些网站没有SSL。
不建议因为更新而修改Wordpress的核心,但我可以控制。