使用Docker + Puma + Nginx部署Rails 5应用程序

我真的很费劲将我的Rails应用程序部署到我新创build的DigitalOcean液滴。

我的设置如下:

我有一个在Docker容器中使用PostgresRedis的本地Rails 5应用程序。

我只是想部署到生产使用Puma + Nginx作为networking服务器。

我无法做到这一点为我的生活。 这是我的docker-compose.yml文件:

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 / Nginxconfiguration正确的服务在生产这样一个简单的应用程序? 我一直在寻找,但似乎无法弄清楚。

提前致谢!

如果您的导轨应用程序部署严格滴,而不是在docker,你可以尝试简单的configuration如下:

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_to_your_app/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"