Dealing with nginx 400 “The plain HTTP request was sent to HTTPS port” error

后端 未结 8 926
不思量自难忘°
不思量自难忘° 2020-11-28 02:04

I\'m running a Sinatra app behind passenger/nginx. I\'m trying to get it to respond to both http and https calls. The problem is, when both are defined in the server block h

相关标签:
8条回答
  • 2020-11-28 02:58

    I ran into a similar problem. It works on one server and does not on another server with same Nginx configuration. Found the the solution which is answered by Igor here http://forum.nginx.org/read.php?2,1612,1627#msg-1627

    Yes. Or you may combine SSL/non-SSL servers in one server:

    server {
      listen 80;
      listen 443 default ssl;
    
      # ssl on   - remember to comment this out
    
    }
    
    0 讨论(0)
  • 2020-11-28 02:59

    Here is an example to config HTTP and HTTPS in same config block with ipv6 support. The config is tested in Ubuntu Server and NGINX/1.4.6 but this should work with all servers.

    server {
        # support http and ipv6
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        # support https and ipv6
        listen 443 default_server ssl;
        listen [::]:443 ipv6only=on default_server ssl;
    
        # path to web directory
        root /path/to/example.com;
        index index.html index.htm;
    
        # domain or subdomain
        server_name example.com www.example.com;
    
        # ssl certificate
        ssl_certificate /path/to/certs/example_com-bundle.crt;
        ssl_certificate_key /path/to/certs/example_com.key;
    
        ssl_session_timeout 5m;
    
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
        ssl_prefer_server_ciphers on;
    }
    

    Don't include ssl on which may cause 400 error. The config above should work for

    http://example.com

    http://www.example.com

    https://example.com

    https://www.example.com

    Hope this helps!

    0 讨论(0)
提交回复
热议问题