我正在尝试在nginx+apache反向代理配置上安装新的Wordpress。我的安装过程如下:
安装的nginx和apache服务器将nginx(下面的conf)配置为代理apache服务器(在端口8080上侦听)
生成了让我们使用带有nginx插件的certbot加密SSL证书。com,setup file ownership/permissions运行wordpress安装,生成配置并添加HTTPS详细信息(下面的conf)我打算只允许通过HTTPS访问此站点,因此我已设置nginx conf将所有流量重定向到端口443。
/etc/nginx/mysite.com:
server {
root /var/www/mysite.com;
index index.php index.html index.htm;
server_name mysite.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \\.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme; # scheme: https
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name mysite.com;
return 404; # managed by Certbot
}
wp-config.php:
<?php
define( \'DB_NAME\', \'x\' );
...
define( \'NONCE_SALT\', \'x\' );
$table_prefix = \'wp_\';
define( \'WP_DEBUG\', false );
if ( $_SERVER[\'HTTP_X_FORWARDED_PROTO\'] == \'https\' )
{
$_SERVER[\'HTTPS\'] = \'on\';
$_SERVER[\'SERVER_PORT\'] = \'443\';
define(\'FORCE_SSL_ADMIN\', true);
}
if ( isset($_SERVER[\'HTTP_X_FORWARDED_HOST\'])) {
$_SERVER[\'HTTP_HOST\'] = $_SERVER[\'HTTP_X_FORWARDED_HOST\'];
}
if ( ! defined( \'ABSPATH\' ) ) {
define( \'ABSPATH\', dirname( __FILE__ ) . \'/\' );
}
require_once( ABSPATH . \'wp-settings.php\' );
使用此安装,我可以访问/wp admin/而没有任何问题,但是当我尝试访问主站点时,我遇到了重定向循环。Chrome网络控制台显示:
有人能解决这个问题吗?我在各种网站上尝试了许多解决方案,包括一些声称可以为您管理SSL页面设置的插件,但都没有成功。如果您需要更多详细信息,请随时询问!
EDIT:来自每个重定向的原始响应:
HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.0 (Ubuntu)
Date: Sun, 10 Mar 2019 16:35:06 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Connection: keep-alive
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
X-Redirect-By: WordPress
Location: https://example.com/
当我尝试请求/时,我得到一个301永久移动响应,告诉我资源已移动到/,从而导致重定向循环。