1 问题
服务器安装了ssl证书,在nginx配置了https监听的443端口后,只能收到https的请求,http请求被拦截了
2 原nginx配置ssl写法
server {
listen 443;
server_name localhost;
ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/a.pem;
ssl_certificate_key cert/a.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;
location / {
root html;
index index.html index.htm;
}
}
3 https和http共存nginx配置写法
server {
listen 80;
listen 443 ssl;
server_name localhost;
#ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/a.pem;
ssl_certificate_key cert/a.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;
location / {
root html;
index index.html index.htm;
}
}
4 小结
实现https和http共存只需要改动三个地方
listen 80;
listen 443 ssl;
#ssl on;
意思是只有443端口是https方式访问,80端口还是http方式访问。
另开启了ssl,网站就不能有非https的资源引用了。