Nginx 400 Bad Request The plain HTTP request was sent to HTTPS port

jackxiang 2018-8-12 23:47 | |
背景:ssl on打开后直接访问Http,出现400错,想能通过Http访问到,得注释掉ssl on;即可。
Problem
When viewing any of my sites using port 80, the following error appeared on non-SSL websites:

Nginx 400 Bad Request The plain HTTP request was sent to HTTPS port
Original server block:

server {
    listen 80;
    listen 443;

    ssl on;
    ssl_certificate         /path/to/cert/example.pem;
    ssl_certificate_key     /path/to/cert/example.private.key;

    root /path/to/wordpress;
    index index.php;

    # Website URL
    server_name blog.duaneleem.com;

    # etc...
}


Solution
After reading NGINX documentation, the solution to this was to place the SSL directive on “listen.” Here’s a sample server block that demonstrates this:

server {
    listen 80;
    listen 443 ssl;

    ssl_certificate         /path/to/cert/example.pem;
    ssl_certificate_key     /path/to/cert/example.private.key;

    root /path/to/wordpress;
    index index.php;

    # Website URL
    server_name blog.duaneleem.com;

    # etc...
}
By adding “ssl” to the listen directive to all my server blocks, everything started working again.


From: https://blog.duaneleem.com/nginx-ssl-on/

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/9853/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!

评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]