php - 非 https 在 AWS EC2 Nginx 上下载 wp-header 文件,但 SSL 有效吗?

标签 php wordpress ssl nginx

我遇到一个非常随机的问题。每当我通过 http 协议(protocol)访问我的网站时,都会下载 wp-blog-header.php 文件,或者我只是从 cloudflare(我正在使用的)那里收到 502 错误。该文件内容如下:

<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');

当我通过 https 协议(protocol)访问网站时,我没有遇到这个问题。

站点是:https://somersetbaby.com

我的 wp-config.php 文件中有以下内容

define('WP_HOME','https://somersetbaby.com');
define('WP_SITEURL','https://somersetbaby.com');

下面是我的站点的 nginx 配置文件:

    server {

    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    ssl     on;
    ssl_certificate         /not/here/somersetbaby.pem;
    ssl_certificate_key     /not/here/somersetbaby.key;

server_name somersetbaby.com   www.somersetbaby.com;


access_log /var/log/nginx/somersetbaby.com.access.log rt_cache;
error_log /var/log/nginx/somersetbaby.com.error.log;


root /var/www/somersetbaby.com/htdocs;



index index.php index.html index.htm;


include common/wpfc-php7.conf;

include common/wpcommon-php7.conf;
include common/locations-php7.conf;
    include /var/www/somersetbaby.com/conf/nginx/*.conf;

我也有一个默认文件,但如果我删除它,我会收到 521 错误,网站将不断重新加载,如果我包含它,我无法让网站强制使用 SSL。

如有任何帮助,我们将不胜感激。

谢谢

最佳答案

这是因为 wordpress 检测 HTTPS 的方式,一个便宜的 hack 是将以下内容放在 wp-config.php

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { 
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

关于php - 非 https 在 AWS EC2 Nginx 上下载 wp-header 文件,但 SSL 有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44765535/

相关文章:

php - 我试图循环遍历类编号的记录集,然后使用 mysql 和 php 从另一个记录集中查询供应

php - 使用 Zend 框架的多条件删除示例

在 WordPress 的 PDF 文件下载链接中检测到 HTML 恶意文件

ssl - 混合 SSL 内容阻止使用 Nginx 安装/操作 Joomla

php - 在 SQL 语句中使用 PHP 变量

php - 如何创建一个按钮来按升序和降序对日期进行排序?

javascript - 修改Superfish菜单jQuery插件

css - WordPress 拆分菜单

azure - 如何通过 Azure API 管理层向微服务添加 HTTPS/SSL 支持,而应用程序服务器不必支持 SSL?

ssl - Kubernetes Ingress SSL 证书无效