nginx增加ssl服务方法
1.将申请到的ssl加密证书文件拷贝到nginx的conf目录下
如:server.pem、server.key
2.vim nginx.conf
例子:
server { listen 443 ssl; #listen 80; server_name www.test.com; ssl_certificate server.pem; ssl_certificate_key server.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers RC4:HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; root /mnt/html/test; index index.php index.html index.htm; access_log logs/test.com_access.log; error_log logs/test.com_error.log debug; error_page 500 502 503 504 /50x.html; location = /50x.html { root /mnt/html; } #重定向 location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; } } location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
3.配置http重定向到https
server { listen 80; server_name www.test.com test.com; rewrite ^(.*)$ https://www.test.com$1 permanent; }
4.重启nginx 搞定
朝朝暮暮.