puma+nginx 服務(wù)器配置

參考

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

項目路徑啟動:

bundle exec puma -e production -b unix:///www/learn_ground/shared/sockets/puma.sock

1. database.yml?

設(shè)置pool,puma默認(rèn)為16

pool: 16

2. config/puma.rb

# Min and Max threads per worker

threads 0, 16

#app_dir = File.expand_path("../..", __FILE__)

#shared_dir = "#{app_dir}/shared"

# Default to production

#rails_env = ENV['RAILS_ENV'] || "production"

environment "production"

# Set up socket location

bind "unix://www/hm_oa5.0/shared/sockets/puma.sock"

# Logging

stdout_redirect "/www/hm_oa5.0/shared/log/puma.stdout.log", "/www/hm_oa5.0/shared/log/puma.stderr.log", true

# Set master PID and state locations

pidfile "/www/hm_oa5.0/shared/pids/puma.pid"

state_path "/www/hm_oa5.0/shared/pids/puma.state"

activate_control_app

#on_worker_boot do

# require "active_record"

#ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished

# A#ctiveRecord::Base.establish_connection(YAML.load_file("/www/hm_oa5.0/config/database.yml")[rails_env])

#end

3. ?/etc/nginx/sites-available

upstream app {

server unix:/www/hm_oa5.0/shared/sockets/puma.sock fail_timeout=0;

}

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

server_name server;

root /www/hm_oa5.0/public;

location ~ ^/assets/ {

gzip_static on;

expires max;

add_header Cache-Control public;

}

try_files $uri/index.html $uri @app;

location @app {

proxy_set_header Host $http_host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_redirect off;

proxy_pass http://app;

proxy_set_header Connection '';

proxy_http_version 1.1;

chunked_transfer_encoding off;

proxy_buffering off;

proxy_cache off;

}

error_page 500 502 503 504 /500.html;

client_max_body_size 4G;

keepalive_timeout 10;

}


注意:

/ect/ ?要有puma.conf

/ect/init/? 要有puma.conf,puma-manager.conf

配置完后 重啟nginx




upstream app {

# Path to Puma SOCK file, as defined previously

server unix:/www/test_hm_oa/shared/sockets/puma.sock fail_timeout=0;

}

server {

listen 9999;

server_name ?server;

root /www/test_hm_oa/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;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容