1# Adapted from https://github.com/gem/oq-qgis-server/blob/master/conf/qgis-server-nginx.conf 2# It requires a FCGI processes spawner like spawn-fcgi or systemd (see s-server-fcgi.socket) 3 4user nginx; 5worker_processes auto; 6access_log /var/log/nginx/access.log; 7error_log /var/log/nginx/error.log; 8pid /run/nginx.pid; 9 10events { 11 worker_connections 1024; 12} 13 14http { 15 16 sendfile on; 17 tcp_nopush on; 18 tcp_nodelay on; 19 keepalive_timeout 65; 20 types_hash_max_size 2048; 21 22 include /etc/nginx/mime.types; 23 default_type application/octet-stream; 24 25 # Get 'host' from `$host` unless 'X-Forwarded-Host' 26 # is set by the reverse proxy. 27 # 'X-Forwarded-Host' may contain also the port, 28 # so it is removed from the variable 29 map $http_x_forwarded_host $qgis_host { 30 "~(?<h>[^:]+)" $h; 31 default $host; 32 } 33 # Get 'PORT' from `$http_host` 34 map $http_host $port { 35 "~*.*:(?<p>.*)" $p; 36 default $server_port; 37 } 38 # Get 'HTTPS' status from `$https` unless 'X-Forwarded-Proto' 39 # is set by the reverse proxy and contains 'https' scheme 40 map $http_x_forwarded_proto $qgis_ssl { 41 "https" "on"; 42 default $https; 43 } 44 # Get 'PORT' from `$port` unless 'X-Forwarded-Port' 45 # is set by the reverse proxy 46 map $http_x_forwarded_port $qgis_port { 47 "" $port; 48 default $http_x_forwarded_port; 49 } 50 51 server { 52 listen 80 default_server; 53 listen [::]:80 default_server; 54 server_name _; 55 root /usr/share/nginx/html; 56 57 location /ows/ { 58 rewrite ^/ows/(.*)$ /qgis/qgis_mapserv.fcgi?map=/var/www/ows/$1.qgs; 59 } 60 location /qgis/ { 61 internal; # Used only by the OGC rewrite 62 root /var/www/ows; 63 fastcgi_pass localhost:9993; 64 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 65 fastcgi_param QUERY_STRING $query_string; 66 # build links in GetCapabilities based on 67 # the hostname exposed by the reverse proxy 68 fastcgi_param HTTPS $qgis_ssl; 69 fastcgi_param SERVER_NAME $qgis_host; 70 fastcgi_param SERVER_PORT $qgis_port; 71 include fastcgi_params; 72 } 73 error_page 404 /404.html; 74 location = /40x.html { 75 } 76 error_page 500 502 503 504 /50x.html; 77 location = /50x.html { 78 } 79 } 80 81} 82