# location of mongrel servers to proxy too upstream mongrel_<%= application.gsub('.', '_') %> { <% mongrel_port.upto(mongrel_port + mongrel_servers) do |port| %> server 127.0.0.1:<%= port %>; <% end %> } server { # port to listen on. Can also be set to an IP:PORT listen 80 <%= "default" if nginx_default_app %>; # set max size for file uploads to 50mb client_max_body_size 50M; # sets the domain[s] that this vhost server requests for # if two apps are on this box remove the ip and setup your hosts file server_name <%= nginx_server_names %>; # doc root root <%= current_path %>/public; # vhost specific logs access_log <%= shared_path %>/log/<%= application %>.access.log main; error_log <%= shared_path %>/log/<%= application %>.error.log notice; # this rewrites all the requests to the maintenance.thml 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; } # block access to paths containing .svn location ~* ^.*\.svn.*$ { internal; } location / { <%= "include /etc/nginx/vhosts/#{application}.auth.conf" if nginx_http_auth_app %> index index.html index.htm; # forward the user's IP address to Rails proxy_set_header X-Real-IP $remote_addr; # needed for HTTPS must add an additional server block to configure it. # see "The Rails Way" page 665 for more info proxy_set_header X-FORWARD_PROTO https; # Forward information about the client and host # Otherwise our Rails app wouldn't have access to it 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; # use this as a reference for a full production deployment # do not use on a dev box. this adds far futures expires. <%= "#" if nginx_far_future %> location ~ ^/(images|javascripts|stylesheets)/ { <%= "#" if nginx_far_future %> expires 10y; <%= "#" if nginx_far_future %> } # if file exists break execution and serve up file for example files in images, javascripts, and stylesheets if (-f $request_filename) { break; } # Rails page caching, if file path plus index.html exists break execution and serve up file if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } # Rails page caching, if file.html exists break execution and serve up file if (-f $request_filename.html) { rewrite (.*) $1.html break; } # if file does not exist forward to mongrel if (!-f $request_filename) { proxy_pass http://mongrel_<%= application.gsub('.', '_') %>; break; } } <% for location in nginx_auth_locations %> location <%= location %> { <%= "include /etc/nginx/vhosts/#{application}.auth.conf" %> } <% end %> # must be an error so point to error page. error_page 500 502 503 504 /500.html; location = /500.html { root <%= current_path %>/public; } }