데비안에서 사용하던 방법입니다. 다음과 같은 환경에서 동작합니다.
- 미디어위키 설치 디렉토리: /var/www/html/w
- 웹 접근 경로: wiki.example.com
- 기사 접근 경로: /wiki/Page_Title
먼저 /etc/nginx/site-available/default를 다음과 같이 설정합니다.
server {
...
root /var/www/html/w;
index index.html index.htm index.nginx-debian.html index.php;
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/wiki([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ^~ /maintenance/ {
return 403;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
try_files $uri /index.php;
expires 7d;
log_not_found off;
}
location = /_.gif {
expires max;
empty_gif;
}
...
}
그런 다음 미디어위키 설정 LocalSettings.php를 다음과 같이 수정합니다.
$wgScriptPath = "";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;