如何使用 nginx 或 apache 部署puma,这是可能的,或者没有必要使用像nginx或apache这样的Web服务器。使用 puma 部署应用的最佳方式是什么?
答案 0 :(得分:2)
密钥位于网站的nginx conf中。
server {
listen 80;
server_name mysite.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:4000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
正如您所看到proxy_pass http://localhost:4000;
行告诉nginx在端口 4000 收听localhost,您可以根据需要进行更改。
使用ssl letsencrypt这是一个很小的改动,当然你应该用letsencrypt配置ssl。
server {
listen 80;
server_name example.com;
location / {
return 301 https://example.com$request_uri;
}
}
server {
listen 443 ssl http2;
server_name example.com;
#listen [::]:443 ssl http2 ipv6only=on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
ssl_trusted_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
include /etc/nginx/snippets/ssl.conf;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:4000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
答案 1 :(得分:1)
由于Puma不是设计用户直接访问的,我们将使用Nginx作为反向代理,它将缓冲用户和Rails应用程序之间的请求和响应。除了工作进程之外,Puma还使用线程来更多地利用可用的CPU。 Nginx和puma之间的通信是通过socket实现的:
如果您需要解释如何使用Puma和Nginx检查部署应用程序this