Last active
April 22, 2018 18:22
-
-
Save mygoare/d503842ed88a78267dbc4c0f245093bb to your computer and use it in GitHub Desktop.
rails nginx puma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 可以 rake secret 生成 | |
export SECRET_KEY_BASE=057c9fbe11080f88f5eb4d56a2e62d725d3bf630a2c5979e91d70a0ddc39a477228c0de47848645df813338a67fbb9bca0902580933b654657257edaea29dc99 | |
export RAILS_ENV=production | |
export RAILS_SERVE_STATIC_FILES=false | |
RAILS_ENV=production rails db:migrate | |
RAILS_ENV=production rails assets:precompile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/nginx/conf.d/ folder | |
server{ | |
listen 80; | |
server_name www.bamket.com; | |
access_log /var/log/list_access.log; | |
error_log /var/log/list_error.log; | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to displaying a 404. | |
try_files $uri $uri/ =404; | |
alias /home/ubuntu/; # alias 这里最后目录一定要加 /,否则nginx会自动截掉最后一个字符 | |
gzip_static on; | |
expires max; | |
add_header Cache-Control public; | |
autoindex on; | |
autoindex_exact_size off; | |
proxy_http_version 1.1; | |
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/nginx/conf.d/ folder | |
upstream my_app { | |
server unix:/home/ubuntu/run/mp.sock; | |
} | |
server { | |
listen 80; | |
server_name mp.bamket.com; | |
# 如果 需要 ssl | |
listen 443 ssl; | |
ssl_certificate /home/ubuntu/ssl/mp_bamket_com.crt; | |
ssl_certificate_key /home/ubuntu/ssl/mp_bamket_com_private.key; | |
root /home/ubuntu/mp/public; | |
access_log /var/log/mp_access.log; | |
error_log /var/log/mp_error.log; | |
try_files $uri/index.html $uri @my_app; | |
location / { | |
proxy_pass http://my_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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 添加这些在头部 | |
project_path = "#{File.expand_path("../..", __FILE__)}" | |
project_name = File.basename(project_path) | |
user_home_path = ENV.fetch("HOME"){ "/home/ubuntu" } | |
pidfile "#{user_home_path}/run/#{project_name}.pid" | |
bind "unix://#{user_home_path}/run/#{project_name}.sock" | |
directory project_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment