NGINX Redirection vers HTTPS ne fonctionne qu’après actualisation

Je veux que le trafic passe par https://example.com . Aucun préfixe www n’est autorisé et SSL est requirejs .

Le problème que nous rencontrons est que de nombreux visiteurs (mais pas tous) ne sont pas redirigés vers HTTPS tant qu’ils n’ont pas été actualisés.

Voyez-vous quelque chose dans ma configuration qui permettrait ce comportement?

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 Ssortingct-Transport-Security "max-age=63072000; includeSubDomains; preload"; client_max_body_size 200m; location / { try_files $uri $uri/ /index.php?$query_ssortingng; 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; } 

Comme @PeeHaa l’a mentionné, vous manquez une redirection de http à https pour http://www.example.com. Essayez ceci où j’ai réarrangé un peu les blocs de serveur pour append un en-tête HSTS au serveur www et pour corriger une erreur de sécurité potentielle où http://www est directement redirigé vers https://(notwww) (par https: / /wiki.mozilla.org/Security/Guidelines/Web_Security#HTTP_Redirections ):

 # 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 Ssortingct-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 Ssortingct-Transport-Security "max-age=63072000; includeSubDomains; preload"; client_max_body_size 200m; location / { try_files $uri $uri/ /index.php?$query_ssortingng; 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; }