我在 Rails v7.0.1 的生产模式下不断收到此错误,HTTP parse error, malformed request: #<Puma::HttpParserError: Invalid HTTP format, parsing fails. Are you trying to open an SSL connection to a non-SSL Puma?
我不知道为什么。我尝试了其他解决方案的所有内容,这些解决方案主要与本地环境相关,但我一直在生产中得到它。
我已经设置config.force_ssl
为true
.
Nginx 会议
server {
listen 80;
listen [::]:80;
server_name api.example.com;
return 308 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name api.example.com;
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/api.exaple.com/privkey.pem; # managed by Certbot
location / {
proxy_pass http://1.1.1.1:3000;
proxy_redirect http://1.1.1.1:3000 https://api.example.com;
}
}
以前这个设置对我有用。请帮忙,我现在要疯了。
宝石文件
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.0.0'
gem 'pg', '>= 1.1'
gem 'puma', '~> 5.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 7.0.0'
gem 'bootsnap', require: false
gem 'jwt'
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'
group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'spring'
end
group :development do
gem 'solargraph'
end