public
Description: Capistrano recipes, plugins and templates.
Homepage: http://capitate.rubyforge.org
Clone URL: git://github.com/gabriel/capitate.git
capitate / lib / templates / nginx / nginx_vhost_generic.conf.erb
100644 99 lines (80 sloc) 2.715 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# 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 %>