分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

https和http共存的nginx配置

发布时间:2023-09-06 02:19责任编辑:彭小芳关键词:配置nginxhttp
原来有一个域名是http://www.art-china.club

但现在都流行加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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved