如何为 http 和 https 请求设置 Nginx

hel*_*y77 3 configuration nginx

我需要设置 Nginx 以便它响应 http 和 https 请求;我以这种方式配置了我的默认配置:

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;
  }
}
Run Code Online (Sandbox Code Playgroud)

https 协议工作正常,但如果我发出 http 请求,则会收到此错误:

400 Bad Request
The plain HTTP request was sent to HTTPS port
Run Code Online (Sandbox Code Playgroud)

Lek*_*eyn 6

SSL指令启用SSL整个虚拟主机,不看的端口号。如果要将 SSL 限制为单个端口,请替换:

  listen       80;
  listen       443;
  ssl           on;
Run Code Online (Sandbox Code Playgroud)

经过:

  listen       80;
  listen       443 ssl;
Run Code Online (Sandbox Code Playgroud)

http://nginx.org/r/listen