1 upstream nominatim_service {
2 <% if node[:nominatim][:api_flavour] == "php" %>
3 server unix:/run/php/php-nominatim.openstreetmap.org-fpm.sock fail_timeout=0;
4 <% elsif node[:nominatim][:api_flavour] == "python" %>
5 server unix:/run/gunicorn-nominatim.openstreetmap.org.sock fail_timeout=0;
9 map $uri $nominatim_script_name {
15 map $uri $nominatim_path_info {
21 ~(^|&)format=html(&|$) html;
25 map $uri/$format $forward_to_ui {
29 ~/reverse.*/default 0;
34 map $query_string $email_id {
35 ~(^|&)email=([^&]+) $2;
38 map $email_id $missing_email {
43 map $http_user_agent $missing_ua {
48 map $http_referer $missing_referer {
56 <% @frontends.each do |frontend| -%>
57 <% frontend.ipaddresses(:role => :external).sort.each do |address| -%>
67 2620:52:3:1:5054:ff:fe0a:75a4 1; # gnome
68 2620:52:3:1:5054:ff:fe0a:75a2 1; # gnome
69 2620:52:3:1:5054:ff:fe0a:75aa 1; # gnome
70 34.234.151.67 1; # gnome - https://github.com/openstreetmap/operations/issues/1160
71 54.165.53.199 1; # gnome - https://github.com/openstreetmap/operations/issues/1160
72 35.153.15.118 1; # gnome - https://github.com/openstreetmap/operations/issues/1160
75 map $server_protocol$http_user_agent $cleaned_user_agent {
76 default $http_user_agent;
77 "~^HTTP/1..Mozilla/" Script$http_user_agent;
80 map $missing_email$missing_referer$cleaned_user_agent $blocked_user_agent {
82 "11" 2; # block any requests without identifier
83 include <%= @confdir %>/nginx_blocked_user_agent.conf;
86 map $missing_email$missing_ua$http_referer $blocked_referrer {
88 include <%= @confdir %>/nginx_blocked_referrer.conf;
91 map $missing_referer$missing_ua$email_id $blocked_email {
93 include <%= @confdir %>/nginx_blocked_email.conf;
96 map $whitelisted $limit_www {
98 0 $binary_remote_addr;
101 map $blocked_user_agent $limit_tarpit {
103 1 $binary_remote_addr;
104 2 $binary_remote_addr;
107 map $missing_email$missing_referer$http_user_agent $generic_mozilla {
113 map $whitelisted$generic_mozilla$uri $limit_reverse {
115 ~01/reverse.* $binary_remote_addr;
116 ~02/reverse.* $binary_remote_addr;
119 limit_req_zone $limit_www zone=www:50m rate=2r/s;
120 limit_req_zone $limit_tarpit zone=tarpit:10m rate=1r/s;
121 limit_req_zone $binary_remote_addr zone=blocked:10m rate=20r/m;
122 limit_req_zone $limit_reverse zone=reverse:10m rate=10r/m;
125 listen 80 default_server;
126 listen [::]:80 default_server;
128 access_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-access.log combined;
129 error_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-error.log;
131 location /nginx_status {
139 rewrite ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 permanent;
142 return 301 https://$host$request_uri;
148 listen 443 ssl http2 default_server;
150 listen [::]:443 ssl http2 default_server;
151 server_name localhost;
153 ssl_certificate /etc/ssl/certs/<%= node[:fqdn] %>.pem;
154 ssl_certificate_key /etc/ssl/private/<%= node[:fqdn] %>.key;
156 root <%= @directory %>/static-website;
159 access_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-access.log combined;
160 error_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-error.log;
162 location /nginx_status {
170 error_page 403 /403.html;
172 limit_req zone=blocked burst=5;
175 error_page 429 /509.html;
177 limit_req zone=blocked burst=5;
181 try_files $uri $uri/ @php;
185 alias <%= @ui_directory %>/dist/;
190 add_header Access-Control-Allow-Origin "*" always;
193 location ~* ^/(search|reverse)(\.php)?/ {
194 error_page 404 /404-old-search-syntax.html;
199 if ($forward_to_ui) {
200 rewrite ^(/[^/]*) https://$host/ui$1.html redirect;
202 if ($blocked_user_agent ~ ^2$)
204 if ($blocked_referrer)
208 if ($args ~* "q=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[ &]")
210 include <%= @confdir %>/nginx_blocked_generic.conf;
212 limit_req zone=www burst=10;
213 limit_req zone=tarpit burst=5;
214 limit_req zone=reverse burst=5;
215 limit_req_status 429;
216 <% if node[:nominatim][:api_flavour] == "php" %>
217 fastcgi_pass nominatim_service;
218 include fastcgi_params;
219 fastcgi_param QUERY_STRING $args;
220 fastcgi_param PATH_INFO "$nominatim_path_info";
221 fastcgi_param SCRIPT_FILENAME "<%= @directory %>/website/$nominatim_script_name";
222 <% elsif node[:nominatim][:api_flavour] == "python" %>
224 if ($request_method = 'OPTIONS') {
225 add_header 'Content-Type' 'text/plain; charset=UTF-8';
226 add_header 'Content-Length' 0;
227 add_header Access-Control-Allow-Origin "*";
228 add_header Access-Control-Allow-Methods 'GET,OPTIONS';
229 add_header Access-Control-Allow-Headers $http_access_control_request_headers;
233 proxy_set_header Host $http_host;
234 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
235 proxy_set_header X-Forwarded-Proto $scheme;
237 proxy_pass http://nominatim_service;
241 <% if node[:nominatim][:api_flavour] == "php" %>
243 if ($blocked_user_agent ~ ^2$)
245 if ($blocked_referrer)
249 include <%= @confdir %>/nginx_blocked_generic.conf;
251 limit_req zone=www burst=10;
252 limit_req zone=tarpit burst=2;
253 limit_req zone=reverse burst=5;
254 limit_req_status 429;
255 fastcgi_pass nominatim_service;
256 include fastcgi_params;
257 fastcgi_param SCRIPT_FILENAME <%= @directory %>/website/$fastcgi_script_name;
259 if ($forward_to_ui) {
260 rewrite (.*).php https://$host/ui$1.html redirect;