Created
May 13, 2017 05:09
-
-
Save qqpann/18e47a3e670fa0f22580cc44523c16d5 to your computer and use it in GitHub Desktop.
Nginx + Unicorn + Rails ref: http://qiita.com/Qiuqiu/items/7bda50ca4a6777f02272
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
$ brew install nginx | |
$ cd /usr/local/etc/nginx | |
$ cp nginx.conf.default nginx.conf | |
$ cp nginx.conf nginx.conf.YYYYMMDD | |
$ vi nginx.conf |
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
upstream unicorn { | |
# nginxとunicornの連携 | |
# unicorn.rbで設定したunicorn.sockを指定 | |
server unix:{RAILS_PROJECT_ROOT}/tmp/unicorn.sock; | |
} | |
server { | |
listen 8081; | |
server_name {PROJECTDOMAIN_FOR_LOCAL}; | |
root {RAILS_PROJECT_ROOT}/public; | |
access_log /usr/local/var/log/nginx/{PROJECT_NAME}_access.log; | |
error_log /usr/local/var/log/nginx/{PROJECT_NAME}_error.log; | |
client_max_body_size 100m; | |
error_page 500 502 503 504 /500.html; | |
try_files $uri/index.html $uri @unicorn; | |
location @unicorn { | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_pass http://unicorn; | |
} | |
} |
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
nginx | |
nginx #sudo必要 |
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
Unicornのログ出力先を指定 | |
#File.expand_pathはパスを絶対パスに解決するメソッド File.expand_path: https://ruby-doc.org/core-2.2.0/File.html#method-c-expand_path | |
rails_root = File.expand_path('../../', __FILE__) | |
#ワーカー数を指定する | |
worker_processes 2 | |
working_directory rails_root | |
listen "#{rails_root}/tmp/unicorn.sock" #??「Unicornのプロセスをlistenするアドレストポートを指定」らしいが… | |
pid "#{rails_root}/tmp/unicorn.pid" #pid fileの位置を指定する | |
#ログの出力先を指定 | |
stderr_path "#{rails_root}/log/unicorn_error.log" | |
stdout_path "#{rails_root}/log/unicorn.log" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment