2016-10-25 13 views
3

https://example.comにトラフィックを送信します。 wwwプレフィックスはありませんとなります。SSLが必要ですNGINX HTTPSへのリダイレクトは、更新後にのみ動作します。

私たちが経験している問題は、リフレッシュするまで初めての多くの訪問者がHTTPSにリダイレクトされていないことです。

私の設定でこの動作を許可するものはありますか?

server { 
    listen 80; 
    listen 443 ssl; 

    server_name www.example.com; 

    return 301 https://example.com$request_uri; 
} 

server { 
    listen 80; 
    listen 443 ssl; 

    server_name example.com; 

    root /var/www/html/mm; 

    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_set_header X-Forwarded-Port 443; 
    proxy_set_header Host $http_host; 

    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; 

    client_max_body_size 200m; 

    location/{ 
     try_files $uri $uri/ /index.php?$query_string; 
     index index.php index.html index.htm install.php; 
     client_max_body_size 200m; 
    } 

    location ~ \.php$ { 
     try_files $uri /index.php =404; 
     #fastcgi_pass unix:/var/run/php-fpm/www.sock; 
     fastcgi_pass php-fpm; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
     fastcgi_param PHP_VALUE "upload_max_filesize = 150M \n upload_max_filesize=151M"; 
     fastcgi_param PHP_VALUE "post_max_size = 150M \n post_max_size=151M"; 
     include fastcgi_params; 
    } 
+0

HTTPをリダイレクトすることはありません - > https:人々が 'www.'なしで入る場合。リフレッシュ後は、HSTSヘッダーのために動作します。 – PeeHaa

+0

最初のブロックでは、 'return 301 https://example.com$request_uri;'がリダイレクトです。 – Justin

+0

はい、人が「*」と入力した場合です。 – PeeHaa

答えて

2

@PeeHaaに記載されているように、httpからwww.example.comのhttpsにリダイレクトされていません。私は、WWWサーバにHSTSヘッダを追加し、http://wwwが直接(https://wiki.mozilla.org/Security/Guidelines/Web_Security#HTTP_Redirectionsにつき)https://(notwww)にリダイレクトされる潜在的なセキュリティmisconfigに対処するために、サーバー・ブロックを少し再配置しましたところ、これを試してみてください:

# HTTP server (non-www) -- redirect to https://example.com 
server { 
    listen 80; 
    server_name example.com; 
    return 301 https://example.com$request_uri; 
} 

# HTTP server (www) -- redirect to https://www.example.com 
server { 
    listen 80; 
    server_name www.example.com; 
    return 301 https://www.example.com$request_uri; 
} 

# HTTPS server (www) -- redirect to https://example.com -- Add HSTS header 
server { 
    listen 443 ssl; 
    server_name www.example.com; 
    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; 
    return 301 https://example.com$request_uri; 
} 

# HTTPS server (non-www) 
server { 
    listen 80; 
    listen 443 ssl; 

    server_name example.com; 

    root /var/www/html/mm; 

    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_set_header X-Forwarded-Port 443; 
    proxy_set_header Host $http_host; 

    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; 

    client_max_body_size 200m; 

    location/{ 
     try_files $uri $uri/ /index.php?$query_string; 
     index index.php index.html index.htm install.php; 
     client_max_body_size 200m; 
    } 

    location ~ \.php$ { 
     try_files $uri /index.php =404; 
     #fastcgi_pass unix:/var/run/php-fpm/www.sock; 
     fastcgi_pass php-fpm; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
     fastcgi_param PHP_VALUE "upload_max_filesize = 150M \n upload_max_filesize=151M"; 
     fastcgi_param PHP_VALUE "post_max_size = 150M \n post_max_size=151M"; 
     include fastcgi_params; 
    } 
関連する問題