I need to set Nginx so it responds to http and https requests; I configured my default conf in this way:

server {
  listen       80;
  listen       443;
  ssl           on;
  ssl_certificate       /etc/nginx/certs/domain-bundle.crt;
  ssl_certificate_key   /etc/nginx/certs/domain.it.key;
  server_name  static.domain.it;
  location / {
    try_files $uri @s3cache;

  location @s3cache{
    proxy_cache            S3CACHE;
    proxy_cache_valid      200 48h;
    proxy_cache_valid      403 60m;
    proxy_pass http://static.domain.it.s3-external-3.amazonaws.com;

The https protocol works fine, but if I make an http request, I get this error:

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

The ssl directive enables SSL for the whole vhost and does not look at the port number. If you want to restrict SSL to a single port, replace:

  listen       80;
  listen       443;
  ssl           on;


  listen       80;
  listen       443 ssl;

See http://nginx.org/r/listen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.