【问题标题】:Non https downloads wp-header file on AWS EC2 Nginx, but SSL Works?非 https 在 AWS EC2 Nginx 上下载 wp-header 文件,但 SSL 有效?
【发布时间】:2017-11-29 15:17:16
【问题描述】:

我遇到了一个非常随机的问题。每当我通过 http 协议访问我的网站时,都会下载 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 协议访问该站点时,我没有遇到此问题。

网站是: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。

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: php wordpress ssl nginx


    【解决方案1】:

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

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

    【讨论】:

    • 也适用于 Cloudflare -&gt; Load Balancer -&gt; NGINX -&gt; LXC Container 后面的 Wordpress 类型设置。
    • 我把它放到 wp-config 文件中,我重新启动了 nginx,并从 cloudflare 中清除了我的缓存。仍然有同样的问题。我也没有在 AWS 上使用负载均衡器,这是一个简单的 Ubuntu 实例安装和 easyengine wordpress 安装(使用 FastCGI 和 PHP7)。
    • 我得到 502 错误的 HTTP 网关,在您的更改中,nginx 仍在侦听端口 80,community.lxc.systems/t/…
    • 如果我在 nginx conf 文件中添加监听端口 80,我会收到 400 错误。如果我把它拿出来,我会收到 502 错误。我已将您上面提到的代码放在 wp-config 文件中,它仍然存在。这是一个艰难的过程,因为它不应该发生(逻辑上)
    【解决方案2】:

    我确实让它工作了,我不得不查看另一个我正在工作的服务器设置。

    我创建了一个名为 /etc/nginx/conf.d/force-ssl-somersetbaby.com.conf 的文件

    然后它有以下代码:

    server {
        listen 80;
        server_name www.somersetbaby.com somersetbaby.com;
        return 301 https://somersetbaby.com$request_uri;
    }
    

    这似乎起到了作用。我已经重新启动服务器并清除了我的缓存。

    感谢您的所有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-15
      • 2019-07-08
      • 2017-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 2023-03-02
      相关资源
      最近更新 更多