但现在都流行加SSL证书,实现https的访问,今天实验了下非常的简单,配置如下:
现在https://www.art-china.club 也可以正常访问了
将域名的证书文件1_www.domain.com_bundle.crt 、私钥文件2_www.domain.com.key保存到同一个目录,例如/usr/local/nginx/conf目录下。
更新Nginx根目录下 conf/nginx.conf 文件如下:
server {
listen ??????80;
listen ?????443 ssl;
server_name ?test.xx.com;
index index.html index.htm index.php;
root /usr/local/default;
?????????ssl_certificate 1_www.domain.com_bundle.crt; ???ssl_certificate_key 2_www.domain.com.key; ???ssl_session_timeout 5m; ???ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置 ???ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置 ???ssl_prefer_server_ciphers on; ???location ~ .*\.(php|php5)?$ ???{ ???????????#fastcgi_pass ?unix:/tmp/php-cgi.sock; ???????????fastcgi_pass ?127.0.0.1:9000; ???????????fastcgi_index index.php; ???????????include fastcgi.conf; ???} ???location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ ???{ ???????????#expires 30d; ???} ???location ~ .*\.(js|css)?$ ???{ ???????????#expires 1h; ???} ???access_log ?logs/test.access.log;
}
配置完成后,先用bin/nginx –t来测试下配置是否有误,正确无误的话,重启nginx。就可以使用 https 来访问了。
证书申请请到你的域名服务商出申请阿里云和腾讯都有免费的证书。
阿里云:https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=2uqqq683
腾讯云:https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=0138fdf13409ab6836352f2816a0f8f8&from=console
https和http共存的nginx配置
原文地址:http://blog.51cto.com/dnuser/2309647