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
72 map $missing_email$missing_referer$http_user_agent $blocked_user_agent {
74 "11" 2; # block any requests without identifier
75 include <%= @confdir %>/nginx_blocked_user_agent.conf;
78 map $missing_email$missing_ua$http_referer $blocked_referrer {
80 include <%= @confdir %>/nginx_blocked_referrer.conf;
83 map $missing_referer$missing_ua$email_id $blocked_email {
85 include <%= @confdir %>/nginx_blocked_email.conf;
88 map $whitelisted $limit_www {
90 0 $binary_remote_addr;
93 map $blocked_user_agent $limit_tarpit {
95 1 $binary_remote_addr;
96 2 $binary_remote_addr;
99 map $missing_email$missing_referer$http_user_agent $generic_mozilla {
105 map $whitelisted$generic_mozilla$uri $limit_reverse {
107 ~01/reverse.* $binary_remote_addr;
108 ~02/reverse.* $binary_remote_addr;
111 limit_req_zone $limit_www zone=www:50m rate=2r/s;
112 limit_req_zone $limit_tarpit zone=tarpit:10m rate=1r/s;
113 limit_req_zone $binary_remote_addr zone=blocked:10m rate=20r/m;
114 limit_req_zone $limit_reverse zone=reverse:10m rate=10r/m;
117 listen 80 default_server;
118 listen [::]:80 default_server;
120 access_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-access.log combined;
121 error_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-error.log;
123 location /nginx_status {
131 rewrite ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 permanent;
134 return 301 https://$host$request_uri;
140 listen 443 ssl http2 default_server;
142 listen [::]:443 ssl http2 default_server;
143 server_name localhost;
145 ssl_certificate /etc/ssl/certs/<%= node[:fqdn] %>.pem;
146 ssl_certificate_key /etc/ssl/private/<%= node[:fqdn] %>.key;
148 <% if node[:nominatim][:api_flavour] == "php" %>
149 root <%= @directory %>/website;
151 root <%= @directory %>/static-website;
155 access_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-access.log combined;
156 error_log <%= node[:nominatim][:logdir] %>/nominatim.openstreetmap.org-error.log;
158 location /nginx_status {
166 error_page 403 /403.html;
168 limit_req zone=blocked burst=5;
171 error_page 429 /509.html;
173 limit_req zone=blocked burst=5;
177 try_files $uri $uri/ @php;
181 alias <%= @ui_directory %>/dist/;
186 add_header Access-Control-Allow-Origin "*" always;
190 if ($blocked_user_agent ~ ^2$)
192 if ($blocked_referrer)
196 include <%= @confdir %>/nginx_blocked_generic.conf;
198 limit_req zone=www burst=10;
199 limit_req zone=tarpit burst=5;
200 limit_req zone=reverse burst=5;
201 limit_req_status 429;
202 <% if node[:nominatim][:api_flavour] == "php" %>
203 fastcgi_pass nominatim_service;
204 include fastcgi_params;
205 fastcgi_param QUERY_STRING $args;
206 fastcgi_param PATH_INFO "$nominatim_path_info";
207 fastcgi_param SCRIPT_FILENAME "<%= @directory %>/website/$nominatim_script_name";
208 <% elsif node[:nominatim][:api_flavour] == "python" %>
209 proxy_set_header Host $http_host;
210 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
211 proxy_set_header X-Forwarded-Proto $scheme;
213 proxy_pass http://nominatim_service;
215 if ($forward_to_ui) {
216 rewrite ^(/[^/]*) https://$host/ui$1.html redirect;
220 <% if node[:nominatim][:api_flavour] == "php" %>
222 if ($blocked_user_agent ~ ^2$)
224 if ($blocked_referrer)
228 include <%= @confdir %>/nginx_blocked_generic.conf;
230 limit_req zone=www burst=10;
231 limit_req zone=tarpit burst=2;
232 limit_req zone=reverse burst=5;
233 limit_req_status 429;
234 fastcgi_pass nominatim_service;
235 include fastcgi_params;
236 fastcgi_param SCRIPT_FILENAME <%= @directory %>/website/$fastcgi_script_name;
238 if ($forward_to_ui) {
239 rewrite (.*).php https://$host/ui$1.html redirect;