我在passenger/nginx后面运行Sinatra应用程序。我正在尝试让它同时响应http和https调用。问题是,当两者都在服务器块中定义时,https调用可以正常响应,但http会产生一个400 "The plain HTTP request is sent to HTTPS port“错误。这是一个静态页面,所以我猜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;
}
发布于 2012-01-11 06:53:39
我遇到了类似的问题。它可以在一台服务器上运行,但不能在另一台Nginx配置的服务器上运行。找到了由Igor here http://forum.nginx.org/read.php?2,1612,1627#msg-1627回答的解决方案
是。或者,您可以将SSL/非SSL服务器组合到一台服务器中:
server {
listen 80;
listen 443 default ssl;
# ssl on - remember to comment this out
}
发布于 2012-09-27 05:04:55
上述答案在大多数情况下是不正确的,因为它覆盖了“is this connection HTTPS”测试,以允许在http上提供寻呼,而不考虑连接安全性。
安全答案使用错误页面上的NGINX特定的http 4xx错误代码,以重定向客户端,以重试相同的请求到https。(如此处所述的https://serverfault.com/questions/338700/redirect-http-mydomain-com12345-to-https-mydomain-com12345-in-nginx )
操作员应该使用:
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://$server_name:$server_port$request_uri;
[....]
}
发布于 2012-01-08 00:36:48
这个错误实际上说明了一切。您的配置告诉Nginx侦听端口80 (HTTP)并使用SSL。当你将浏览器指向http://localhost
时,它会尝试通过超文本传输协议连接。因为Nginx需要SSL,所以它会报错。
解决方法非常简单。您需要两个server
部分:
server {
listen 80;
// other directives...
}
server {
listen 443;
ssl on;
// SSL directives...
// other directives...
}
https://stackoverflow.com/questions/8768946
复制相似问题