server { listen 80; rewrite ^ (. *) $ https://$server _name$1 permanent; server_name example.com; if ( "$host" != ' example.com ' ) { rewrite ^/(. *) $ http:// example.com/$1 permanent; } access_log logs/web.log main; location / { root web Directory; index index.php index.html ; } location ~ \.php$ { root web directory; fastcgi_pass unix:/dev/shm/php-fpm.socket; fastcgi_index index.php; fastcgi_param script_filename web Directory $fastcgi_script_name; include fastcgi_params; }}server { listen 443; ssl on; ssl_certificate /usr/local/data/nginx/conf/ Https.pem; ssl_ certificate_key /usr/local/data/nginx/conf/https.key; ssl_session_timeout 5m; ssl_ciphers ecdhe-rsa-aes128-gcm-sha256:ecdhe:ecdh:aes:high:! null:!anull:! md5:! Adh:! Rc4; ssl_ protocols tlsv1 tlsv1.1 tlsv1.2; ssl_prefer_server_ciphers on; access_log logs/access_web.log; location / { root web Directory; index index.php index.html; } location ~ \.php$ { root web Directory; fastcgi_pass unix:/dev/shm/php-fpm.socket; fastcgi_index index.php; fastcgi_param script_filename web Directory $fastcgi_script_name; include fastcgi_params; }}Attention
Rewrite ^ (. *) $ https://$server _name$1 permanent;
This is a forced redirect, which can be accessed at the same time after HTTP and HTTPS are removed
This article from "Do not abandon!" Do not give up "blog, be sure to keep this source http://thedream.blog.51cto.com/6427769/1933409
Nginx switch HTTPS certificate on-line