Created
January 12, 2015 14:40
-
-
Save noriaki/57e5d3f1077b8c4805a9 to your computer and use it in GitHub Desktop.
CentOS+Rails4+Apache2.2でPumaを動かす設定 ref: http://qiita.com/noriaki/items/74ee4877c0989a42399b
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
% mkdir -p tmp/pids | |
% mkdir -p tmp/sockets |
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 about | |
About your application's environment | |
Rails version 4.2.0 | |
Ruby version 2.1.5-p273 (x86_64-linux) | |
RubyGems version 2.4.4 | |
Rack version 1.5 |
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
% puma --version | |
puma version 2.10.2 |
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
% /usr/sbin/httpd -v | |
Server version: Apache/2.2.15 (Unix) | |
Server built: Oct 16 2014 14:48:21 |
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
% inxi -SM | |
System: Host: hakone.vps.sakura.ne.jp Kernel: 2.6.32-431.1.2.0.1.el6.x86_64 x86_64 (64 bit) | |
Console: tty 1 Distro: CentOS release 6.6 (Final) | |
Machine: System: Red Hat product: KVM v: RHEL 6.4.0 PC | |
Mobo: N/A model: N/A Bios: Sea v: 0.5.1 date: 01/01/2007 |
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
# -*- coding: utf-8; mode: conf; -*- | |
# Redirect all requests that don't match a file on disk | |
# under DocumentRoot get proxied to Puma | |
RewriteEngine On | |
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f | |
# Don't allow client to fool Puma into thinking connection is secure | |
RequestHeader unset X-Forwarded-Proto | |
# Disable ETags (https://github.com/h5bp/server-configs-apache/tree/master/doc#configure-etags) | |
# Set Expiration date for all assets to one year in the future | |
<locationmatch "^/assets/.*$"> | |
Header unset ETag | |
FileETag None | |
ExpiresActive On | |
ExpiresDefault "access plus 1 year" | |
</locationmatch> | |
# Rewrite requests for js and css to gzipped versions | |
# if client and server support it | |
<locationmatch "^/assets/.*\.(css|js)$"> | |
RewriteEngine on | |
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b | |
RewriteCond %{REQUEST_FILENAME}.gz -s | |
RewriteRule ^(.+)$ $1.gz | |
</locationmatch> | |
# Set type and headers for gzipped css | |
<locationmatch "^/assets/.*\.css\.gz$"> | |
ForceType text/css | |
Header set Content-Encoding gzip | |
Header add Vary Accept-Encoding | |
</locationmatch> | |
# Set type and headers for gzipped js | |
<locationmatch "^/assets/.*\.js\.gz$"> | |
ForceType application/javascript | |
Header set Content-Encoding gzip | |
Header add Vary Accept-Encoding | |
</locationmatch> | |
# Compress HTML on the fly | |
AddOutputFilterByType DEFLATE text/html |
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
require 'active_support' | |
require 'active_support/core_ext' | |
rails_root = Dir.pwd | |
unless ENV['RACK_ENV'] == 'production' | |
environment ENV['RACK_ENV'] || 'development' | |
daemonize true # デーモン化 | |
workers 0 # 1以上を指定するとCluster化する | |
threads 0,2 # スレッド数(最小, 最大) | |
bind 'unix://' + File.join(rails_root, 'tmp', 'sockets', 'puma.sock') # /PATH/TO/MYAPP/tmp/sockets/puma.sock | |
port 9293 # Port番号 | |
pidfile File.join(rails_root, 'tmp', 'pids', 'puma.pid') # /PATH/TO/MYAPP/tmp/pids/puma.pid | |
state_path File.join(rails_root, 'tmp', 'puma.state') # /PATH/TO/MYAPP/tmp/puma.state | |
stdout_redirect( # pumaのログをlog/以下に出力する。trueは追記モード。 | |
File.join(rails_root, 'log', 'puma.log'), | |
File.join(rails_root, 'log', 'puma-error.log'), | |
true | |
) | |
# pumactlのトークンを指定 via. http://qiita.com/takkkun/items/ecdee7e7dec1bcc9a5b5 | |
activate_control_app('auto', auth_token: rails_root.camelize.parameterize) | |
end |
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
# -*- coding: utf-8; mode: conf; -*- | |
## | |
# MYAPP | |
# | |
<virtualhost *:80> | |
DocumentRoot "/PATH/TO/MYAPP/public" # Railsアプリのpublicディレクトリを指定 | |
ServerName myapp.example.com # Railsアプリのドメインを指定 | |
RewriteLog logs/MYAPP-rewrite_log | |
RewriteLogLevel 1 | |
ErrorLog logs/MYAPP-error_log | |
CustomLog logs/MYAPP-access_log combined env=!no_log | |
SetEnv RACK_ENV developmen # Railsアプリの実行環境(development/test/production) | |
# for puma config | |
include conf.d/puma-conf # ここでPuma共通設定ファイルを読み込んでいる | |
RewriteRule ^/(.*)$ http://0.0.0.0:9293%{REQUEST_URI} [P] # '9293'のところにはconf/puma.rbで指定したPort番号を設定 | |
<directory "/PATH/TO/MYAPP/public"> | |
AllowOverride All | |
Options FollowSymLinks -MultiViews | |
Order deny,allow | |
Allow from all | |
</directory> | |
</virtualhost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment