OLD | NEW |
1 server | 1 expires 1d; |
| 2 |
| 3 root /var/www/<%= vhost %>; |
| 4 index index; |
| 5 default_type text/html; |
| 6 |
| 7 <% if custom_config %> |
| 8 <%= custom_config %> |
| 9 <% end %> |
| 10 |
| 11 # Match Accept-Language header against available languages |
| 12 |
| 13 set $preferredLang ""; |
| 14 if ($http_accept_language ~ ^(\w\w)-(\w\w)\b) |
2 { | 15 { |
3 <% if is_default %> | 16 set $preferrredLang $1_$2; |
4 listen 80 default_server; | 17 } |
5 listen [::]:80 default_server; | 18 if (!-f $document_root/$preferredLang/index) |
6 <% else %> | 19 { |
7 listen 80; | 20 set $preferredLang ""; |
8 listen [::]:80; | |
9 <% end %> | |
10 | |
11 server_name '<%= vhost %>'; | |
12 | |
13 location / | |
14 { | |
15 rewrite (.*) https://<%= vhost %>$1 permanent; | |
16 } | |
17 } | 21 } |
18 | 22 |
19 server | 23 set $temp "$preferredLang|$http_accept_language"; |
| 24 if ($temp ~ ^\|(\w\w)\b) |
20 { | 25 { |
21 <% if is_default %> | 26 set $preferredLang $1; |
22 listen 443 ssl default_server; | 27 } |
23 listen [::]:443 ssl default_server; | 28 if (!-f $document_root/$preferredLang/index) |
24 <% else %> | 29 { |
25 listen 443 ssl; | |
26 listen [::]:443 ssl; | |
27 <% end %> | |
28 | |
29 server_name '<%= vhost %>'; | |
30 | |
31 ssl_certificate sites-available/adblockplus.org_sslcert.pem; | |
32 ssl_certificate_key sites-available/adblockplus.org_sslcert.key; | |
33 | |
34 expires 1d; | |
35 | |
36 root /var/www/<%= vhost %>; | |
37 index index; | |
38 default_type text/html; | |
39 | |
40 <% if custom_config %> | |
41 <%= custom_config %> | |
42 <% end %> | |
43 | |
44 # Match Accept-Language header against available languages | |
45 | |
46 set $preferredLang ""; | 30 set $preferredLang ""; |
47 if ($http_accept_language ~ ^(\w\w)-(\w\w)\b) | |
48 { | |
49 set $preferrredLang $1_$2; | |
50 } | |
51 if (!-f $document_root/$preferredLang/index) | |
52 { | |
53 set $preferredLang ""; | |
54 } | |
55 | |
56 set $temp "$preferredLang|$http_accept_language"; | |
57 if ($temp ~ ^\|(\w\w)\b) | |
58 { | |
59 set $preferredLang $1; | |
60 } | |
61 if (!-f $document_root/$preferredLang/index) | |
62 { | |
63 set $preferredLang ""; | |
64 } | |
65 | |
66 if ($preferredLang = "") | |
67 { | |
68 set $preferredLang "en"; | |
69 } | |
70 | |
71 # Always redirect server root | |
72 | |
73 rewrite ^/$ /$preferredLang/ last; | |
74 | |
75 # Don't do anything if requested file exists | |
76 | |
77 if (-f $request_filename) | |
78 { | |
79 break; | |
80 } | |
81 if (-d $request_filename) | |
82 { | |
83 break; | |
84 } | |
85 | |
86 # Redirect canonical URLs to language-specific versions | |
87 | |
88 set $canonical $uri; | |
89 if ($canonical ~ ^(.*?)\?) | |
90 { | |
91 set $canonical $1; | |
92 } | |
93 | |
94 if (-f $document_root/$preferredLang$canonical) | |
95 { | |
96 rewrite ^ /$preferredLang$canonical last; | |
97 } | |
98 if (-f $document_root/en$canonical) | |
99 { | |
100 rewrite ^ /en$canonical last; | |
101 } | |
102 | |
103 <% if @multiplexer_locations %> | |
104 <% @multiplexer_locations.each do |location| %> | |
105 location <%= location %> | |
106 { | |
107 fastcgi_pass unix:/tmp/multiplexer-fastcgi.sock; | |
108 include /etc/nginx/fastcgi_params; | |
109 } | |
110 <% end %> | |
111 <% end %> | |
112 } | 31 } |
113 | 32 |
114 <% if @aliases %> | 33 if ($preferredLang = "") |
115 <% @aliases.each do |vhost_alias| %> | 34 { |
116 server | 35 set $preferredLang "en"; |
117 { | 36 } |
118 listen 80; | |
119 listen [::]:80; | |
120 listen 443 ssl; | |
121 listen [::]:443 ssl; | |
122 | 37 |
123 server_name '<%= vhost_alias %>'; | 38 # Always redirect server root |
124 | 39 |
125 ssl_certificate sites-available/adblockplus.org_sslcert.pem; | 40 rewrite ^/$ /$preferredLang/ last; |
126 ssl_certificate_key sites-available/adblockplus.org_sslcert.key; | |
127 | 41 |
128 location / | 42 # Don't do anything if requested file exists |
129 { | 43 |
130 rewrite .* https://<%= vhost %>/ redirect; | 44 if (-f $request_filename) |
131 } | 45 { |
132 } | 46 break; |
| 47 } |
| 48 if (-d $request_filename) |
| 49 { |
| 50 break; |
| 51 } |
| 52 |
| 53 # Redirect canonical URLs to language-specific versions |
| 54 |
| 55 set $canonical $uri; |
| 56 if ($canonical ~ ^(.*?)\?) |
| 57 { |
| 58 set $canonical $1; |
| 59 } |
| 60 |
| 61 if (-f $document_root/$preferredLang$canonical) |
| 62 { |
| 63 rewrite ^ /$preferredLang$canonical last; |
| 64 } |
| 65 if (-f $document_root/en$canonical) |
| 66 { |
| 67 rewrite ^ /en$canonical last; |
| 68 } |
| 69 |
| 70 <% if @multiplexer_locations %> |
| 71 <% @multiplexer_locations.each do |location| %> |
| 72 location <%= location %> |
| 73 { |
| 74 fastcgi_pass unix:/tmp/multiplexer-fastcgi.sock; |
| 75 include /etc/nginx/fastcgi_params; |
| 76 } |
133 <% end %> | 77 <% end %> |
134 <% end %> | 78 <% end %> |
OLD | NEW |