|
| 1 | +user www-data; |
| 2 | +worker_processes 1; |
| 3 | +daemon off; |
| 4 | + |
| 5 | +error_log /proc/self/fd/2 warn; |
| 6 | +pid /var/run/nginx.pid; |
| 7 | + |
| 8 | + |
| 9 | +events { |
| 10 | + worker_connections 1024; |
| 11 | +} |
| 12 | + |
| 13 | + |
| 14 | +http { |
| 15 | + include /etc/nginx/mime.types; |
| 16 | + default_type application/octet-stream; |
| 17 | + |
| 18 | + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| 19 | + '$status $body_bytes_sent "$http_referer" ' |
| 20 | + '"$http_user_agent" "$http_x_forwarded_for"'; |
| 21 | + |
| 22 | + access_log /proc/self/fd/2 main; |
| 23 | + |
| 24 | + sendfile on; |
| 25 | + #tcp_nopush on; |
| 26 | + |
| 27 | + keepalive_timeout 65; |
| 28 | + |
| 29 | + server { |
| 30 | + listen 80 default_server; |
| 31 | + server_name wiki.emfcamp.org; |
| 32 | + root /var/www/mediawiki; |
| 33 | + client_max_body_size 32M; |
| 34 | + client_body_timeout 60; |
| 35 | + |
| 36 | + set_real_ip_from 192.168.0.0/16; |
| 37 | + set_real_ip_from 172.16.0.0/12; |
| 38 | + set_real_ip_from 10.0.0.0/8; |
| 39 | + real_ip_header X-Forwarded-For; |
| 40 | + |
| 41 | + location ~ ^/(?<year>20[0-9][0-9])/ { |
| 42 | + alias /var/www/mediawiki/; |
| 43 | + index index.php; |
| 44 | + |
| 45 | + if (!-f /config/$year/LocalSettings.php) { return 404; } |
| 46 | + |
| 47 | + location ~ ^/[^/]+/$ { |
| 48 | + return 301 /$year/wiki/; |
| 49 | + } |
| 50 | + |
| 51 | + location ~ ^/([^/]+)/w/images/(.*)$ { |
| 52 | + location ~* \.php$ { return 403; } |
| 53 | + location ~ ^/[^/]+/w/images/deleted { return 403; } |
| 54 | + alias /images/$1/$2; |
| 55 | + } |
| 56 | + |
| 57 | + location ~ ^/[^/]+/w/ { |
| 58 | + rewrite ^/[^/]+/w/(.*)$ /w/$1 last; |
| 59 | + } |
| 60 | + |
| 61 | + location ~ ^/[^/]+/wiki/ { |
| 62 | + rewrite ^/[^/]+/wiki/(.*)$ /w/index.php/$1 last; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + location ~ \.php(/|$) { |
| 67 | + # $request_filename takes into account alias, unlike $fastcgi_script_name, |
| 68 | + # but isn't affected by $fastcgi_split_path_info. So we rewrite it instead. |
| 69 | + # As we're inside a location, no more locations are checked. |
| 70 | + rewrite ^/(.+?\.php)(?<path_info>/.*)$ /$1; |
| 71 | + |
| 72 | + # Examples for https://wiki-archive.emfcamp.org/2018/w/test.php/x: |
| 73 | + # return 301 $fastcgi_script_name; # /2018/w/test.php |
| 74 | + # return 301 $fastcgi_path_info; # would be /x, but is empty because we don't split |
| 75 | + # return 301 $request_filename; # /var/www/mediawiki/w/test.php |
| 76 | + # return 301 $path_info; # /x |
| 77 | + # return 301 $uri; # /2018/w/test.php |
| 78 | + # return 301 $request_uri; # /2018/w/test.php/x |
| 79 | + |
| 80 | + if (!-f $request_filename) { |
| 81 | + return 404; |
| 82 | + } |
| 83 | + |
| 84 | + include fastcgi_params; |
| 85 | + fastcgi_param SCRIPT_FILENAME $request_filename; |
| 86 | + fastcgi_param PATH_INFO $path_info; |
| 87 | + fastcgi_param HTTP_PROXY ""; |
| 88 | + |
| 89 | + fastcgi_pass unix:/var/run/mediawiki.sock; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + server { |
| 94 | + listen 80; |
| 95 | + server_name badge.emfcamp.org badge.localhost; |
| 96 | + root /var/www/mediawiki; |
| 97 | + client_max_body_size 32M; |
| 98 | + client_body_timeout 60; |
| 99 | + |
| 100 | + set_real_ip_from 192.168.0.0/16; |
| 101 | + set_real_ip_from 172.16.0.0/12; |
| 102 | + set_real_ip_from 10.0.0.0/8; |
| 103 | + real_ip_header X-Forwarded-For; |
| 104 | + |
| 105 | + index index.php; |
| 106 | + |
| 107 | + location = / { |
| 108 | + return 301 wiki/; |
| 109 | + } |
| 110 | + |
| 111 | + location /w/images/ { |
| 112 | + location ~* \.php$ { return 403; } |
| 113 | + location /w/images/deleted { return 403; } |
| 114 | + alias /images/badge/; |
| 115 | + } |
| 116 | + |
| 117 | + location /wiki/ { |
| 118 | + rewrite ^/wiki/(.*)$ /w/index.php/$1 last; |
| 119 | + } |
| 120 | + |
| 121 | + location ~ \.php(/|$) { |
| 122 | + # $request_filename takes into account alias, unlike $fastcgi_script_name, |
| 123 | + # but isn't affected by $fastcgi_split_path_info. So we rewrite it instead. |
| 124 | + # As we're inside a location, no more locations are checked. |
| 125 | + rewrite ^/(.+?\.php)(?<path_info>/.*)$ /$1; |
| 126 | + |
| 127 | + # Examples for https://wiki-archive.emfcamp.org/2018/w/test.php/x: |
| 128 | + # return 301 $fastcgi_script_name; # /2018/w/test.php |
| 129 | + # return 301 $fastcgi_path_info; # would be /x, but is empty because we don't split |
| 130 | + # return 301 $request_filename; # /var/www/mediawiki/w/test.php |
| 131 | + # return 301 $path_info; # /x |
| 132 | + # return 301 $uri; # /2018/w/test.php |
| 133 | + # return 301 $request_uri; # /2018/w/test.php/x |
| 134 | + |
| 135 | + if (!-f $request_filename) { |
| 136 | + return 404; |
| 137 | + } |
| 138 | + |
| 139 | + include fastcgi_params; |
| 140 | + fastcgi_param SCRIPT_FILENAME $request_filename; |
| 141 | + fastcgi_param PATH_INFO $path_info; |
| 142 | + fastcgi_param HTTP_PROXY ""; |
| 143 | + |
| 144 | + fastcgi_pass unix:/var/run/mediawiki.sock; |
| 145 | + } |
| 146 | + } |
| 147 | +} |
0 commit comments