nginx配置https和http共存
服务器安装 ssl证书, nginx配置 https监听的443端口后,只能收到https的请求,http请求被拦截了,想二个共存乍么办


原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;
}
}

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;
}
}

实现https和http共存只需要改动三个地方
listen 80;
listen 443 ssl;
#ssl on; 默认关闭ssl,不然网站就不能有非https的资源引用了。意思是只有443端口是https方式访问,80端口还是http方式访问