Ruby on rails 使用Docker+部署Rails 5应用程序;美洲狮+;Nginx
我真的很难将Rails应用程序部署到我新创建的DigitalOcean droplet上 我的设置如下: 我有一个本地的Rails 5应用程序,在Docker容器中有Postgres和Redis 我只想使用Puma+Nginx作为Web服务器将其部署到生产环境中 为了我的生命,我无法做到这一点。这是我的docker-compose.yml文件:Ruby on rails 使用Docker+部署Rails 5应用程序;美洲狮+;Nginx,ruby-on-rails,postgresql,docker,nginx,puma,Ruby On Rails,Postgresql,Docker,Nginx,Puma,我真的很难将Rails应用程序部署到我新创建的DigitalOcean droplet上 我的设置如下: 我有一个本地的Rails 5应用程序,在Docker容器中有Postgres和Redis 我只想使用Puma+Nginx作为Web服务器将其部署到生产环境中 为了我的生命,我无法做到这一点。这是我的docker-compose.yml文件: version: "2" services: postgres: image: postgres:9.6 ports:
version: "2"
services:
postgres:
image: postgres:9.6
ports:
- "5432:5432"
environment:
POSTGRES_DB: "${DATABASE_NAME}"
POSTGRES_PASSWORD: "${DATABASE_PASSWORD}"
volumes:
- postgres-data:/var/lib/postgresql/data
redis:
image: redis:latest
ports:
- "6379:6379"
volumes:
# This allows the data to persist to disk without being lost on
# Docker container restarts:
postgres-data:
driver: local
在生产中为这样一个简单的应用程序提供服务的正确Puma/Nginx配置是什么?我一直在寻找,但似乎找不出答案
提前谢谢 如果您的rails应用程序严格部署到droplet,而不是docker,您可以尝试以下简单配置: nginx.conf
upstream your_app {
server unix:/path_to_app_home/shared/tmp/sockets/puma.sock
fail_timeout=0;
}
server {
listen 80;
server_name yor_domain.tld;
root /path_to_app/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @your_app;
location @your_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://your_app;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 1G;
}
/path\u到您的应用程序/shared/config/puma.rb
environment "production"
bind "unix:///path_to_your_app/shared/tmp/sockets/puma.sock"
pidfile "/path_to_your_app/shared/tmp/pids/puma.pid"
state_path "/path_to_your_app/shared/tmp/sockets/puma.state"
directory "/path_to_your_app/current"
workers 1
threads 1,2
daemonize true
activate_control_app 'unix:///path_to_your_app/shared/tmp/sockets/pumactl.sock'
prune_bundler
stdout_redirect "/path_to_your_app/shared/log/puma.stdout.log", "/path_to_your_app/shared/log/puma.stderr.log"
只是一些建议:不要在生产中使用Docker作为数据库,除非您完全知道自己在做什么。这是可以做到的,但做对真的很难……是的,我也注意到了……这似乎是一笔相当糟糕的交易。数据没有像我希望的那样持久,等等。可能会摆脱Docker Altogether你是如何设置Puma等的,并保持Puma服务运行的?如果NGINX部署在Docker之外,那么我不明白为什么它的配置真的会和普通的不同。将NGINX直接设置为server/public目录,然后使用unix域套接字并将NGINX代理设置为该目录,或者如果您想要一个完整的TCP套接字,请使用它(默认配置是针对端口3000)。DaniG2k可以将DB数据保留在容器外的卷有什么问题?这就是我最近与docker合作的结果——这显然不能回答这个问题