OLD | NEW |
1 expires 1d; | 1 expires 1d; |
2 | 2 |
3 root /var/www/<%= vhost %>; | 3 root /var/www/<%= vhost %>; |
4 index index; | 4 index index; |
5 default_type text/html; | 5 default_type text/html; |
6 charset utf-8; | 6 charset utf-8; |
7 | 7 |
| 8 set $index_page "index"; |
| 9 |
8 <% if @custom_config %> | 10 <% if @custom_config %> |
9 <%= custom_config %> | 11 <%= custom_config %> |
10 <% end %> | 12 <% end %> |
11 | 13 |
12 # Match Accept-Language header against available languages | 14 location / |
| 15 { |
| 16 # Match Accept-Language header against available languages |
13 | 17 |
14 set $preferredLang ""; | 18 set $preferredLang en; |
15 if ($http_accept_language ~ ^(\w\w)-(\w\w)\b) | 19 set $preferredRegion ""; |
16 { | 20 if ($http_accept_language ~ ^(\w\w)\b) |
17 set $preferrredLang $1_$2; | 21 { |
18 } | 22 set $preferredLang $1; |
19 if (!-f $document_root/$preferredLang/index) | 23 } |
20 { | 24 if ($http_accept_language ~ ^\w\w-(\w\w)\b) |
21 set $preferredLang ""; | 25 { |
22 } | 26 set $preferredRegion $1; |
| 27 } |
23 | 28 |
24 set $temp "$preferredLang|$http_accept_language"; | 29 # Redirect canonical URLs to language-specific versions |
25 if ($temp ~ ^\|(\w\w)\b) | |
26 { | |
27 set $preferredLang $1; | |
28 } | |
29 if (!-f $document_root/$preferredLang/index) | |
30 { | |
31 set $preferredLang ""; | |
32 } | |
33 | 30 |
34 if ($preferredLang = "") | 31 if (-f "$document_root/${preferredLang}_$preferredRegion$uri") |
35 { | 32 { |
36 set $preferredLang "en"; | 33 rewrite ^(.*) /${preferredLang}_$preferredRegion$1 last; |
37 } | 34 } |
| 35 if (-f "$document_root/$preferredLang$uri") |
| 36 { |
| 37 rewrite ^(.*) /$preferredLang$1 last; |
| 38 } |
| 39 if (-f "$document_root/en$uri") |
| 40 { |
| 41 rewrite ^(.*) /en$1 last; |
| 42 } |
38 | 43 |
39 # Always redirect server root | 44 # Redirect server/language root |
40 | 45 |
41 rewrite ^/$ /$preferredLang/ last; | 46 rewrite ^/$ /$index_page last; |
42 | 47 rewrite ^/(\w\w(_\w\w)?)$ /$1/ permanent; |
43 # Don't do anything if requested file exists | 48 rewrite ^/(\w\w(_\w\w)?)/$ /$1/$index_page last; |
44 | |
45 if (-f $request_filename) | |
46 { | |
47 break; | |
48 } | |
49 if (-d $request_filename) | |
50 { | |
51 break; | |
52 } | |
53 | |
54 # Redirect canonical URLs to language-specific versions | |
55 | |
56 set $canonical $uri; | |
57 if ($canonical ~ ^(.*?)\?) | |
58 { | |
59 set $canonical $1; | |
60 } | |
61 | |
62 if (-f $document_root/$preferredLang$canonical) | |
63 { | |
64 rewrite ^ /$preferredLang$canonical last; | |
65 } | |
66 if (-f $document_root/en$canonical) | |
67 { | |
68 rewrite ^ /en$canonical last; | |
69 } | 49 } |
70 | 50 |
71 <% if @multiplexer_locations %> | 51 <% if @multiplexer_locations %> |
72 <% @multiplexer_locations.each do |location| %> | 52 <% @multiplexer_locations.each do |location| %> |
73 location <%= location %> | 53 location <%= location %> |
74 { | 54 { |
75 fastcgi_pass unix:/tmp/multiplexer-fastcgi.sock; | 55 fastcgi_pass unix:/tmp/multiplexer-fastcgi.sock; |
76 include /etc/nginx/fastcgi_params; | 56 include /etc/nginx/fastcgi_params; |
77 } | 57 } |
78 <% end %> | 58 <% end %> |
79 <% end %> | 59 <% end %> |
OLD | NEW |