Nginx配置http和https共存

2018-03-20 23:15:00
937次阅读
0个评论

给nginx配置SSL证书之后,https可以正常访问,http访问显示400错误,nginx的配置如下:


server {
            listen 80 default backlog=2048;
            listen 443;
            server_name xxx.com;
            root /var/www/html;

            ssl on;
            ssl_certificate /usr/local/www/sslcrt/xxx.crt;
            ssl_certificate_key /usr/local/www/sslcrt/xxx.key;
        }
http访问的时候,报错如下:


400 Bad Request
The plain HTTP requset was sent to HTTPS port. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!

信息显示http的请求被发送到https的端口,所以才会出现这样的错误。

将ssl on;这行注释,ssl写在443端口后面。这样http和https的链接都可以用,完美解决。


server {
            listen 80 default backlog=2048;
            listen 443 ssl;
            server_name linuxyan.com;
            root /var/www/html;

            ssl_certificate /usr/local/www/sslcrt/xxx.crt;
            ssl_certificate_key /usr/local/www/sslcrt/xxx.key;
        }


收藏00

登录 后评论。没有帐号? 注册 一个。