2015-12-25 137 views
2

我在我的wordpress網站前添加了一個nginx服務器。此外,我在nginx上添加了我的ssl證書,以便通過https保護我的網站。用ssl和反向代理(nginx)的WordPresspress

隨着我粘貼到這裏,配置如果我訪問前端與twentysixteen主題,我得到的鉻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

這些行添加到wp-config.php

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) 
    && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { 
    $_SERVER['HTTPS'] = 'on'; 
} 
0

而不是添加行wp-config.php,你可以添加以下線直接到Apache VirtualHost配置或.htaccess

SetEnvIf X-Forwarded-Proto https HTTPS=on 

和此行的Apache2配置:

LoadModule setenvif_module libexec/apache22/mod_setenvif.so