簡體   English   中英

rails 5 with puma 和 nginx systemd

[英]rails 5 with puma with nginx systemd

現在我在 DO 中有一個 Droplet 並在 Rails 部署程序中進行實驗。 我在 ubuntu 16 中有一個 rails 5,並且已經完成了所有必要的程序來部署我的應用程序,除了目前卡在 nginx puma 和 systemd 中。 我已經看過 DO 的教程,但問題是他們使用 upstart 作為 init 的腳本。 作為 nginx 和 linux 系統的完全初學者,我不知道如何使用 nginx 啟動我的應用程序。 我做的最后一個程序是

  • 安裝 nginx
  • 測試nginx,它正在運行
  • 將一些配置放在 config/puma.rb* 上

    # Change to match your CPU core count workers 2 # Min and Max threads per worker threads 1, 6 app_dir = File.expand_path("../..", __FILE__) shared_dir = "#{app_dir}/shared" # Default to production rails_env = ENV['RAILS_ENV'] || "production" environment rails_env # Set up socket location bind "unix://#{shared_dir}/sockets/puma.sock" # Logging stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true # Set master PID and state locations pidfile "#{shared_dir}/pids/puma.pid" state_path "#{shared_dir}/pids/puma.state" activate_control_app on_worker_boot do require "active_record" ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished ActiveRecord::Base.establish_connection(YAML.load_file("# {app_dir}/config/database.yml")[rails_env]) end
  • 編輯 /etc/nginx/sites-available/default*

     upstream app { # Path to Puma SOCK file, as defined previously server unix:/home/deploy/appname/shared/sockets/puma.sock fail_timeout=0; } server { listen 80; server_name localhost; root /home/deploy/appname/public; try_files $uri/index.html $uri @app; location @app { proxy_pass http://app; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; }
  • 添加 /etc/systemd/system/puma.service

*基礎來自https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04

這是 puma.service 的代碼

[Unit]
Description=Puma HTTP Server
After=network.target

# Uncomment for socket activation (see below)
# Requires=puma.socket

[Service]
Type=simple
User=(myUser)
WorkingDirectory=/home/(myUser)/apps/(appName)

# ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
# ExecStart=/usr/local/bin/bundle exec --keep-file-descriptors puma -e production
ExecStart=/usr/local/bin/puma -C /home/(myUser)/apps/(appName)/config/puma.rb

Restart=always

[Install]
WantedBy=multi-user.target

我有退出 203,檢查一些東西並發現 /usr/local/bin/puma 在我的 linux 中不存在。

有人可以幫助我設置適當的 systemd 服務嗎? 我真的沒有這方面的經驗,我不知道在 ExecStart 上放什么

如果尚未安裝puma ,請安裝。

使用which puma找出puma的安裝位置,然后將該路徑放在ExecStart=行上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM