nginx服务器配置ssl证书,站点同时支持http和https访问配置教程
1、获取ssl证书文件(这里在阿里云直接购买免费版)








2、ssl证书配置(nginx配置方法):
在站点配置文件中添加如下内容:
listen 443; ssl_certificate /usr/local/nginx/certs/youhutong.pem; ssl_certificate_key /usr/local/nginx/certs/youhutong.key; ssl on; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on;
如:原始配置文件
server {
listen 80;
server_name www.youhutong.com;
index index.html index.htm index.php;
root /www/web1;
location / {
try_files $uri @apache;
}
location @apache {
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ .*\.(php|php5|cgi|pl)?$ {
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
} 配置好后的配置文件:
server {
listen 80;
listen 443;
# ssl证书文件中的pem文件和key文件存放位置配置
ssl_certificate /usr/local/nginx/cert/youhutong.pem;
ssl_certificate_key /usr/local/nginx/cert/youhutong.key;
ssl on;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
server_name www.youhutong.com;
index index.html index.htm index.php;
root /www/web1;
location / {
try_files $uri @apache;
}
location @apache {
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ .*\.(php|php5|cgi|pl)?$ {
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
}3、把证书放到上面配置指定的文件夹里面去,没有就新建。
4、重启nginx,配置完成(http https都可以访问了)。
【注意】:
如果你使用了阿里云的负载均衡服务或者自己配置负载均衡什么的,上面的还不会有效果,因为负载均衡服务还没有支持https访问。
阿里云负载均衡服务配置ssl证书支持https访问:
1):创建证书(负载均衡管理 -> 证书管理 -> 创建证书 -> 从SSL证书服务选择 -> 选择我们上面已经签发的证书 -> 确认完成)
2):添加监听




转载请注明来源地址:小川编程 » https://www.youhutong.com/index.php/article/index/226.html
1、本站发布的内容仅限用于学习和研究目的.请勿用于商业或非法用途,下载后请24小时内删除。
2、本站所有内容均不能保证其完整性,不能接受请勿购买或下载,如需完整程序,请去其官方购买正版使用
3、本站联系方式Email:admin@youhutong.com ,收到邮件会第一时间处理。
4、如侵犯到任何版权问题,请立即告知本站(立即在线告知),本站将及时删除并致以最深的歉意
