RAILS_ENV=production rake secret /etc/profile export SECRET_KEY_BASE=剛纔生成的密鑰 source /etc/profile
這種簡單的把端口暴露出去, 可能出現服務得不到應答的問題,tcp被各類close_wait阻塞。解決的辦法:架設nginx。html
rails 的web服務主要有puma, unicorn, passenger node
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } threads threads_count, threads_count environment ENV.fetch("RAILS_ENV") { "prodution" } daemonize trueworkers 2 application_path = "/home/apphome" worker_timeout 60 stdout_redirect "#{application_path}/shared/log/puma.stdout.log" state_path "#{application_path}/shared/tmp/sockets/puma.state" pidfile "#{application_path}/shared/tmp/pids/puma.pid" bind "unix://#{application_path}/shared/sockets/app.sock" activate_control_app "unix://#{application_path}/shared/sockets/pumactl.sock" # directory "#{application_path}/current" preload_app!
# 經過ps -aux| grep 查看一下是否啓動,若是沒有啓動成功,把daemonzie註釋掉,就能看到報錯信息。nginx
/etc/nginx/nginx.confweb
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; upstream app { server unix://home/上面puma文件中填的bind路徑.sock; } server { listen 4000 default_server; server_name 0.0.0.0; # 服務器名 root app的根目錄; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Real_IP $remote_addr; proxy_redirect off; proxy_pass http://app; # 這裏填寫upstream的名稱
} keepalive_timeout 10; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
重啓nginx: nginx -t; nginx -s reloadbash