2016-08-22 7 views
0

Nginx Webサーバーv.1.2.1を使用し、Wordpress CMSを使用して、Digital OceanでホストされているWebサイトを持っています。その後、私はCloudflareサービスを利用することに決めました。 Cloudflareは無料のFlexible SSLを提供しており、私は自分のWebサイトに使用したいと思っています。SSL(Digital Ocean + Nginx + Cloudflare)の実装

これは私のウェブサイトのnginxの設定ファイルである:

server { 
     listen 80; 
     #listen [::]:80 ipv6only=on default_server; 
     server_name pasangbatu.com www.pasangbatu.com; 
     root /srv/www/pasangbatu.com/public_html; 
     access_log /srv/www/pasangbatu.com/logs/access.log; 
     error_log /srv/www/pasangbatu.com/logs/error.log; 

     if ($http_host != "www.pasangbatu.com") { 
       rewrite^http://www.pasangbatu.com$request_uri permanent; 
     } 


     index index.php index.html; 
     location = /favicon.ico { 
       log_not_found off; 
       access_log off; 
     } 
     location = /robots.txt { 
       allow all; 
       log_not_found off; 
       access_log off; 
     } 

    # Use gzip compression 
    # gzip_static on; # Uncomment if you compiled Nginx using --with-http_gzip_static_module 
    gzip on; 
    gzip_disable "msie6"; 
    gzip_vary on; 
    gzip_proxied any; 
    gzip_comp_level 5; 
    gzip_buffers 16 8k; 
    gzip_http_version 1.0; 
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg; 

     #location ~ ^/wp-content/cache/minify/[^/]+/(.*)$ { 
     #  try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1; 
     #} 

    #location ~ ^/wp-content/plugins/wp-minify/min/[^/]+/(.*)$ { 
    # try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1; 
    # wp-minify/cache 
    #} 

    # Don't cache uris containing the following segments 
    if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|wp-.*\.php|index\.php|wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") { 
     set $cache_uri "no cache"; 
    } 

    # Don't use the cache for logged in users or recent commenters 
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp\-postpass|wordpress_logged_in") { 
     set $cache_uri 'no cache'; 
    } 



    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
     location ~ /\. { 
       deny all; 
       access_log off; 
       log_not_found off; 
     } 
     location/{ 
       try_files $uri $uri/ /index.php?$args; 
     } 

     # Add trailing slash to */wp-admin requests. 
     rewrite /wp-admin$ $scheme:http://$host$uri/ permanent; 

    # Cache static files for as long as possible - removed xml as an extension to avoid problems with Yoast WordPress SEO plugin which uses WP rewrite API. 
    location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { 
     try_files $uri =404; 
     expires max; 
     access_log off; 
    } 

    # Pass PHP scripts on to PHP-FPM 
    location ~* \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     try_files $uri /index.php; 
     fastcgi_index index.php; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     #fastcgi_pass 127.0.0.1:9000; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_param SCRIPT_NAME $fastcgi_script_name; 
     } 
} 

私はこのような何かにif ($http_host !="www.pasangbatu.com") {を変更しようとしました:

if ($http_host != "www.pasangbatu.com") { 
        rewrite^https://www.pasangbatu.com$request_uri permanent; 
      } 

私は私がSSL対応しまった、nginxのを再起動し、私のWebを更新ホームページ上にしかし、私が別のページに行く/記事のリンクをクリックすると、httpプロトコルに戻るページはhttpsではありません。

私はif condition blockを無効にして、ちょうどこのように書いた場合:

rewrite^https://www.pasangbatu.com$request_uri permanent; 

「多くのリダイレクトするようにかくかくしかじか」私のウェブサイトのリターン。

すべてのマイページにhttpsを有効にするにはどうすればよいですか?あなたの助けが必要です

ありがとうございます。

答えて

1

本質的に、この問題は、フレキシブルSSLを使用しているときにWebサーバーがHTTPを介して接続を認識していることに起因します(原点からブラウザへの接続はHTTPS経由です)。

これを回避するには、Nginx設定のX-Forwarded-Protoヘッダーにフックする必要があります。

CloudFlare Flexible SSL pluginのようなプラグインもご利用いただけます。

CloudFlare's Page Rulesを使用すると、効果的にredirect HTTP to HTTPS trafficを使用することができます。

+0

こんにちは、ありがとうございます。それは私に手がかりを与えた:) –

関連する問題