[英]Running Puma with SSL and Nginx
我有在Rails API上運行的Angular應用程序。
我可以使用SSL為Angular應用提供服務,但是在SSL上運行Rails API時遇到問題。 在production.rb中,我添加了config.force_ssl = true
。 我使用RAILS_ENV=production rails server --binding=*public ip of instance*
運行Rails服務器。 這是我的api的nginx配置文件:
upstream app{
server localhost:3000;
}
server {
listen 80;
listen [::]:80;
server_name api.domain.com;
return 302 https://$server_name$request_uri;
}
server{
#SSL Configuration
listen 443 ssl;
listen [::]:443 ssl;
include snippets/snakeoil.conf;
server_name api.domain.com;
location / {
proxy_pass https://app;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
這是我包含的snakeoil.conf文件:
ssl_certificate /etc/letsencrypt/live/www.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.domain.com/privkey.pem;
當我向api.domain.com發出請求時,出現502錯誤網關錯誤。 Rails拋出此2018-02-19 07:07:02 +0000: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.
這是配置問題嗎?還是我必須更改應用程序代碼中的某些內容?
Puma僅理解http請求,但是您正在強迫它處理https請求。
用“ proxy_pass http:// app ”替換“ proxy_pass https:// app ”應該可以解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.