|
| 1 | +events { |
| 2 | + worker_connections 1024; # Adjust this to your needs |
| 3 | +} |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +http { |
| 8 | + proxy_cache_path /tmp/nginx_ajax_proxy_cache levels=1:2 keys_zone=ajax_proxy:10m inactive=60m; |
| 9 | + proxy_cache_key "$uri$is_args$args"; |
| 10 | + |
| 11 | + map $http_upgrade $connection_upgrade { |
| 12 | + default upgrade; |
| 13 | + '' close; |
| 14 | + } |
| 15 | + |
| 16 | + types { |
| 17 | + application/javascript mjs; |
| 18 | + } |
| 19 | + |
| 20 | + include mime.types; |
| 21 | + default_type application/octet-stream; |
| 22 | + sendfile on; |
| 23 | + keepalive_timeout 65; |
| 24 | + |
| 25 | + # Server block |
| 26 | + server { |
| 27 | + listen 80; |
| 28 | + server_name localhost; |
| 29 | + |
| 30 | + # Static file serving |
| 31 | + location /static/ { |
| 32 | + alias /static/; |
| 33 | + gzip on; |
| 34 | + gzip_vary on; |
| 35 | + gzip_proxied any; |
| 36 | + gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; |
| 37 | + expires 365d; |
| 38 | + access_log /dev/null; |
| 39 | + } |
| 40 | + |
| 41 | + # Geojson files |
| 42 | + location /uploads/ { |
| 43 | + alias /data/; |
| 44 | + expires 30d; |
| 45 | + } |
| 46 | + |
| 47 | + location /favicon.ico { |
| 48 | + alias /static/favicon.ico; |
| 49 | + } |
| 50 | + |
| 51 | + # X-Accel-Redirect |
| 52 | + location /internal/ { |
| 53 | + internal; |
| 54 | + gzip_vary on; |
| 55 | + gzip_static on; |
| 56 | + add_header X-DataLayer-Version $upstream_http_x_datalayer_version; |
| 57 | + alias /data/; |
| 58 | + } |
| 59 | + |
| 60 | + # Ajax proxy |
| 61 | + location ~ ^/proxy/(.*) { |
| 62 | + internal; |
| 63 | + add_header X-Proxy-Cache $upstream_cache_status always; |
| 64 | + proxy_cache_background_update on; |
| 65 | + proxy_cache_use_stale updating; |
| 66 | + proxy_cache ajax_proxy; |
| 67 | + proxy_cache_valid 1m; # Default. Umap will override using X-Accel-Expires |
| 68 | + set $target_url $1; |
| 69 | + # URL is encoded, so we need a few hack to clean it back. |
| 70 | + if ( $target_url ~ (.+)%3A%2F%2F(.+) ){ # fix :// between scheme and destination |
| 71 | + set $target_url $1://$2; |
| 72 | + } |
| 73 | + if ( $target_url ~ (.+?)%3A(.*) ){ # fix : between destination and port |
| 74 | + set $target_url $1:$2; |
| 75 | + } |
| 76 | + if ( $target_url ~ (.+?)%2F(.*) ){ # fix / after port, the rest will be decoded by proxy_pass |
| 77 | + set $target_url $1/$2; |
| 78 | + } |
| 79 | + resolver 8.8.8.8; |
| 80 | + add_header X-Proxy-Target $target_url; # For debugging |
| 81 | + proxy_pass_request_headers off; |
| 82 | + proxy_set_header Content-Type $http_content_type; |
| 83 | + proxy_set_header Content-Encoding $http_content_encoding; |
| 84 | + proxy_set_header Content-Length $http_content_length; |
| 85 | + proxy_read_timeout 10s; |
| 86 | + proxy_connect_timeout 5s; |
| 87 | + proxy_ssl_server_name on; |
| 88 | + proxy_pass $target_url; |
| 89 | + proxy_intercept_errors on; |
| 90 | + error_page 301 302 307 = @handle_proxy_redirect; |
| 91 | + } |
| 92 | + location @handle_proxy_redirect { |
| 93 | + resolver 8.8.8.8; |
| 94 | + set $saved_redirect_location '$upstream_http_location'; |
| 95 | + proxy_pass $saved_redirect_location; |
| 96 | + } |
| 97 | + |
| 98 | + # Proxy pass to ASGI server |
| 99 | + location / { |
| 100 | + proxy_pass http://app:8000; |
| 101 | + proxy_set_header Host $host; |
| 102 | + proxy_set_header X-Real-IP $remote_addr; |
| 103 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 104 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 105 | + proxy_set_header Upgrade $http_upgrade; |
| 106 | + proxy_set_header Connection $connection_upgrade; |
| 107 | + proxy_redirect off; |
| 108 | + proxy_buffering off; |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments