nginx配置一个端口同时支持http和https
其实一个端口不能同时支持http和https,只是在监听到http访问时,重定向到https,从始至终,就只是支持https的访问
目前有两个思路
1.监听http访问会报错,然后重定向到https,当nginx配置ssl后,访问http前端页面会报400,这时nginx也会报错,报497,所以我们可以在nginx监听错误码497,从而再重定向到https
server {
listen 3333 ssl;
server_name localhost;
error_page 497 https://$host:$server_port$request_uri;
}
#重点在于错误码的监听也是写在https的server里,因为是监听一个端口,所以不能写两个server