Skip to content

Instantly share code, notes, and snippets.

@johan--
Forked from yonggu/apache2-unicorn-conf
Created July 5, 2016 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johan--/d0a12d0b203a670c27351932a8724e61 to your computer and use it in GitHub Desktop.
Save johan--/d0a12d0b203a670c27351932a8724e61 to your computer and use it in GitHub Desktop.
Apache 2 configuration file with unicorn in Rails 4
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /rails_app_directory/public
# Redirect all requests that don't match a file on disk under DocumentRoot get proxied to Puma
RewriteEngine On
<Proxy balancer://unicornservers>
BalancerMember http://127.0.0.1:5100
</Proxy>
# RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
# RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
ProxyPass /assets !
ProxyPass / balancer://unicornservers/
ProxyPassReverse / balancer://unicornservers/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Don't allow client to fool Puma into thinking connection is secure
RequestHeader unset X-Forwarded-Proto
# Anything under public is open to the world
<Directory /home/deploy/apps/zuqiutuan_production/current/public>
Require all granted
Options -MultiViews
Satisfy Any
AuthType None
</Directory>
# 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
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment