我在wordpress网站前添加了一个nginx服务器。另外,我在nginx上添加了我的ssl证书,以便通过https保护我的网站。
使用我在此处粘贴的配置,如果我使用twentysixteen主题访问前端,我在chrome JS控制台中收到以下错误:
Mixed Content: The page at 'https://my.website.it/' was loaded over HTTPS, but requested an insecure script 'http://my.website.it/wp-content/themes/twentysixteen/js/functions.js?ver=20150825'. This request has been blocked; the content must be served over HTTPS.
如果我访问https://my.website.it/wp-admin
我被重定向到https://wp-admin/
这是我的wordpress的配置:
以下是Wordpress服务器的配置:
WP-config.php中
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
define('FORCE_SSL_ADMIN','true');
define('WP_SITEURL','https://my.website.it');
define('WP_HOME','https://my.website.it');
我的.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^wploadbalance$ [NC]
RewriteRule ^(.*)$ https://my.website.it/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
这是我的nginx服务器的配置:
server {
listen 80;
server_name my.website.it;
return 301 https://$server_name$request_uri;
}
server {
listen 443;
server_name my.website.it;
ssl on;
ssl_certificate /etc/ssl/certificate/certificate.crt;
ssl_certificate_key /etc/ssl/private/mprivate.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
location / {
proxy_pass http://wploadbalance;
client_max_body_size 20M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_buffers 64 4k;
}
}
upstream wploadbalance{
least_conn;
server wordpress;
}
答案 0 :(得分:0)
将这些行添加到wp-config.php
:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
&& $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
答案 1 :(得分:0)
您可以直接将以下行添加到Apache wp-config.php
配置或VirtualHost
:
.htaccess
添加行。
SetEnvIf X-Forwarded-Proto https HTTPS=on
这行到Apache2配置:
LoadModule setenvif_module libexec/apache22/mod_setenvif.so