#
# Nginx virtual host conf
#
# * Uses cache directory configured for public/cache
# * Re-writes url for iphone user agent to /iphone (so as not to conflict with cache)
# * TODO-gabe: Same for mobile user agents
# * Redirects domain.com to www.domain.com (IMO should be the other way around; www is deprecated)
#
upstream <%= nginx_upstream_name %> {
<% nginx_upstream_ports.each do |port| %>
server 127.0.0.1:<%= port %>;
<% end %>
}
server {
# port to listen on. Can also be set to an IP:PORT.
listen 80;
# Set the max size for file uploads to 50Mb
client_max_body_size 50M;
<% unless domain_name.blank? or domain_name == "localhost" %>
# sets the domain[s] that this vhost server requests for
server_name www.<%= domain_name %>;
<% end %>
# doc root
root <%= public_path %>;
# vhost specific access log
access_log <%= shared_path %>/log/nginx.<%= application %>.access.log main;
# this rewrites all the requests to the maintenance.html
# page if it exists in the doc root. This is for capistrano's
# disable web task
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
location / {
# Uncomment to allow server side includes so nginx can
# post-process Rails content
## ssi on;
proxy_set_header X-Real-IP $remote_addr;
# needed for HTTPS
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_max_temp_file_size 0;
# For iphone unique url
if ($http_user_agent ~* "(iPhone|iPod)") {
rewrite ^/$ /iphone break;
proxy_pass http://<%= nginx_upstream_name %>;
break;
}
if (-f $request_filename) {
break;
}
if (-f $document_root/cache/$uri/index.html) {
rewrite (.*) /cache/$1/index.html break;
}
if (-f $document_root/cache/$uri.html) {
rewrite (.*) /cache/$1.html break;
}
if (-f $document_root/cache/$uri) {
rewrite (.*) /cache/$1 break;
}
if (!-f $request_filename) {
proxy_pass http://<%= nginx_upstream_name %>;
break;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /500.html;
location = /500.html {
root <%= public_path %>;
}
}
<% unless domain_name.blank? or domain_name == "localhost" %>
server {
server_name <%= domain_name %>;
rewrite ^/(.*) http://www.<%= domain_name %>/$1 permanent;
}
<% end %>