nginx syntax tweaks
[rails.git] / config / nginx.conf
1 user www-data www-data;\r
2 worker_processes  2;\r
3 \r
4 error_log  /var/log/nginx/error.log;\r
5 pid        /var/run/nginx.pid;\r
6 \r
7 events {\r
8         # max clients = worker_processes * worker_connections\r
9     worker_connections  1024;\r
10 }\r
11 \r
12 http {\r
13     include       /etc/nginx/mime.types;\r
14     default_type  application/octet-stream;\r
15 \r
16     #access_log  /var/log/nginx/access.log;\r
17 \r
18     sendfile        on;\r
19     #tcp_nopush     on;\r
20 \r
21     #keepalive_timeout  0;\r
22     keepalive_timeout  65;\r
23     tcp_nodelay        on;\r
24 \r
25     gzip  on;\r
26         gzip_min_length 1100;\r
27         gzip_buffers 4 8k;\r
28         # text/html is added gzip_types by default\r
29         gzip_types text/plain application/x-javascript application/x-shockwave-flash text/css;\r
30         \r
31         #NO CGI SUPPORT IN NGINX fix stat .pl later\r
32 \r
33         upstream web_backend {\r
34                 server 127.0.0.1:8000;\r
35                 server 127.0.0.1:8001;\r
36                 server 127.0.0.1:8002;\r
37                 server 127.0.0.1:8003;\r
38                 server 127.0.0.1:8004;\r
39                 server 127.0.0.1:8005;\r
40                 server 127.0.0.1:8006;\r
41                 server 127.0.0.1:8007;\r
42                 server 127.0.0.1:8008;\r
43                 server 127.0.0.1:8009;\r
44                 server 127.0.0.1:8010;\r
45                 server 127.0.0.1:8011;\r
46                 server 127.0.0.1:8012;\r
47                 server 127.0.0.1:8013;\r
48                 server 127.0.0.1:8014;\r
49                 server 127.0.0.1:8015;\r
50                 server 127.0.0.1:8016;\r
51                 server 127.0.0.1:8017;\r
52                 server 127.0.0.1:8018;\r
53                 server 127.0.0.1:8019;\r
54                 server 127.0.0.1:8020;\r
55                 server 127.0.0.1:8021;\r
56                 server 127.0.0.1:8022;\r
57                 server 127.0.0.1:8023;\r
58                 server 127.0.0.1:8024;\r
59                 server 127.0.0.1:8025;\r
60                 server 127.0.0.1:8026;\r
61                 server 127.0.0.1:8027;\r
62                 server 127.0.0.1:8028;\r
63                 server 127.0.0.1:8029;\r
64         }\r
65 \r
66         upstream api_backend {\r
67                 server 127.0.0.1:8030;\r
68                 server 127.0.0.1:8031;\r
69                 server 127.0.0.1:8032;\r
70                 server 127.0.0.1:8033;\r
71                 server 127.0.0.1:8034;\r
72                 server 127.0.0.1:8035;\r
73                 server 127.0.0.1:8036;\r
74                 server 127.0.0.1:8037;\r
75                 server 127.0.0.1:8038;\r
76                 server 127.0.0.1:8039;\r
77                 server 127.0.0.1:8040;\r
78                 server 127.0.0.1:8041;\r
79                 server 127.0.0.1:8042;\r
80                 server 127.0.0.1:8043;\r
81                 server 127.0.0.1:8044;\r
82         }\r
83 \r
84         upstream bulkapi_backend {\r
85                 server 10.0.0.10:8000;\r
86                 server 10.0.0.11:8000;\r
87                 server 10.0.0.12:8000;\r
88                 server 10.0.0.10:8001;\r
89                 server 10.0.0.11:8001;\r
90                 server 10.0.0.12:8001;\r
91                 server 10.0.0.10:8002;\r
92                 server 10.0.0.11:8002;\r
93                 server 10.0.0.12:8002;\r
94                 server 10.0.0.10:8003;\r
95                 server 10.0.0.11:8003;\r
96                 server 10.0.0.12:8003;\r
97         }\r
98         \r
99         upstream tah_backend {\r
100                 server 10.0.0.10:8004;\r
101                 server 10.0.0.11:8004;\r
102                 server 10.0.0.12:8004;\r
103                 server 10.0.0.10:8005;\r
104                 server 10.0.0.11:8005;\r
105                 server 10.0.0.12:8005;\r
106         }\r
107 \r
108 server {\r
109                 listen   80;\r
110                 server_name  .openstreetmap.org api.openstreetmap.org;\r
111                 root /home/rails/public;\r
112                 index index.html;\r
113                 access_log  /var/log/nginx/openstreetmap.org.access.log;\r
114         \r
115                 include /etc/nginx/fastcgi_params;\r
116 \r
117                 #Redirect Historical Links to correct servers\r
118                 location /trac/ {\r
119                         rewrite ^/trac/(.*)$ http://trac.openstreetmap.org/$1 permanent;\r
120                 }\r
121 \r
122                 location /wiki/ {\r
123                         rewrite ^/wiki/(.*)$ http://wiki.openstreetmap.org/$1 permanent;\r
124                 }\r
125 \r
126                 location / {\r
127                         deny 143.210.16.160;\r
128                         deny 69.89.21.73;\r
129                         deny 91.89.145.219;\r
130                         deny 195.190.169.111;\r
131                         deny 84.237.213.10;\r
132                         deny 70.22.219.249;\r
133                         deny 83.226.40.87;\r
134                         deny 82.178.145.87;\r
135                         deny 91.78.50.134;\r
136                         deny 91.77.7.139;\r
137                         deny 85.126.23.106;\r
138                         deny 213.171.196.166;\r
139                         deny 81.151.8.64;\r
140                         deny 130.226.235.215;\r
141                         deny 141.99.254.253;\r
142                         deny 61.228.43.32;\r
143                         allow all; \r
144                 }\r
145         \r
146                 #Handle api.openstreetmap/ -> api.openstreetmap/api/\r
147                 if ($host ~* api\.(.*)) {\r
148                         rewrite ^/(0\.[0-9]+)/(.*)$ /api/$1/$2\r
149                 }\r
150         \r
151                 location /api/ {\r
152                         include /etc/nginx/fastcgi_params;\r
153                         if ($http_user_agent ~ "^tilesAtHome") {\r
154                                 #deny all;\r
155                                 fastcgi_pass tah_backend;\r
156                                 break;\r
157                         }\r
158                 }\r
159 \r
160                 location ~ ^/api/0\.6/(map|relation|trackpoints|amf|amf/read|swf/trackpoints|trace/[0-9]+/data)$ {\r
161                         fastcgi_pass bulkapi_backend;\r
162                         break;\r
163                 }\r
164                 \r
165                 location ~ ^/api/0\.6/.*/search$ {\r
166                         fastcgi_pass bulkapi_backend;\r
167                         break;\r
168                 }\r
169 \r
170                 location ~ ^/api/0\.6/.*/full$ {\r
171                         fastcgi_pass bulkapi_backend;\r
172                         break;\r
173                 }\r
174 \r
175                 # fastcgi Web / Data Browser / Relations etc\r
176                 location ~ ^/api/0\.6/ {\r
177                         fastcgi_pass api_backend;\r
178                         break;\r
179                 }\r
180 \r
181                 #Deny unknown API version\r
182                 location ~ ^/api/0\.[0-9]+/ {\r
183                         deny all;\r
184                 }\r
185                         \r
186                 #Handle Special Case Expiry\r
187                 location ~ ^/(export|openlayers)/ {\r
188                         expires 7d;\r
189                 }\r
190                 location ~ ^/(images|javascripts|stylesheets)/ {\r
191                         expires max;\r
192                 }\r
193         \r
194                 location / {\r
195                         fastcgi_index index.html;\r
196                         if (!-f $request_filename) {\r
197                                 fastcgi_pass web_backend;\r
198                                 break;\r
199                         }\r
200                 }\r
201 \r
202                 location /crossdomain.xml {\r
203                         default_type text/x-cross-domain-policy;\r
204                 }\r
205 \r
206                 #error_page  404  /404.html;\r
207         # redirect server error pages to the static page /50x.html\r
208         error_page   500 502 503 504  /50x.html;\r
209         location = /50x.html {\r
210                         root   /var/www/nginx-default;\r
211                 }\r
212         }\r
213 }\r