【发布时间】:2023-04-03 21:42:01
【问题描述】:
我在乘客/nginx 后面运行一个 Sinatra 应用程序。我试图让它同时响应 http 和 https 调用。问题是,当两者都在服务器块中定义时,https 调用正常响应,但 http 产生 400“普通 HTTP 请求已发送到 HTTPS 端口”错误。这是一个静态页面,所以我猜 Sinatra 与此无关。有关如何解决此问题的任何想法?
这是服务器块:
server {
listen 80;
listen 443 ssl;
server_name localhost;
root /home/myhome/app/public;
passenger_enabled on;
ssl on;
ssl_certificate /opt/nginx/ssl_keys/ssl.crt;
ssl_certificate_key /opt/nginx/ssl_keys/ssl.key;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
location /static {
root /home/myhome/app/public;
index index.html index.htm index.php;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 /500.html;
access_log /home/myhome/app/logs/access.log;
error_log /home/myhome/app/logs/error.log;
}
【问题讨论】:
-
就我而言,浏览器中的网址:
my.example.com:443不起作用。将其改为https://my.example.com有效。奇怪,apache 从来没有这个问题。 -
ssl on;告诉 NGINX 通过 SSL 服务 ANY 内容。在listen 443;的末尾使用“ssl”标志,例如listen 443 ssl;如果您的服务器同时提供 http 和 https 流量,并删除ssl on;指令。
标签: nginx