puma+nginx 服务器配置

参考

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 

设置pool,puma默认为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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容