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

后端 未结 8 963
不思量自难忘°
不思量自难忘° 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:37

    The above answers are incorrect in that most over-ride the 'is this connection HTTPS' test to allow serving the pages over http irrespective of connection security.

    The secure answer using an error-page on an NGINX specific http 4xx error code to redirect the client to retry the same request to https. (as outlined here https://serverfault.com/questions/338700/redirect-http-mydomain-com12345-to-https-mydomain-com12345-in-nginx )

    The OP should use:

    server {
      listen        12345;
      server_name   php.myadmin.com;
    
      root         /var/www/php;
    
      ssl           on;
    
      # If they come here using HTTP, bounce them to the correct scheme
      error_page 497 https://$host:$server_port$request_uri;
    
      [....]
    }
    

提交回复
热议问题