2016-04-05 6 views
4

Nginxを使用してwikiを設定しようとしています。MediaWikiファイルがファイルに見つかりません:短いURLを使用している場合のexample.jpg

は、私はそれが正しく動作/index.php?title=File:image.jpgを使用する場合/wiki/File:image.jpg nginxのは404
を返します使用する場合。

server { 
    listen 80; 
    listen [::]:80 ipv6only=on; 

    root /usr/share/nginx/mediawiki; 
    index index.php index.html index.htm; 

    ... 

    location /wiki/ { 
     index index.php; 
     rewrite ^/wiki/([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last; 
    } 

    location ~* /wiki/images/.*.(html|htm|shtml|php)$ { 
     types { } 
     default_type text/plain; 
    } 

    location ~* /wikiimages/ { 
     try_files $uri /wiki/index.php; 
    } 

    location ~* \.(js|css|jpg|jpeg|png|gif|ico)$ { 
     try_files $uri /wiki/index.php; 
     expires max; 
     log_not_found off; 
    } 

    location ~*\.php?$ { 
     try_files $uri =404; 
    # # With php5-fpm: 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
     include fastcgi_params; 
    } 

    location /wiki/.*\.php?$ { 
     try_files $uri =404; 
    # # With php5-fpm: 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
     include fastcgi_params; 
    } 
} 

答えて

0

静的リソースを直接処理しようとする正規表現を変更しました。

server { 
    ... 

    location ~* \.(js|css|gif|ico)$ { 
     try_files $uri /wiki/index.php; 
     expires max; 
     log_not_found off; 
    } 

    ... 
} 
+0

私のnginxは、リビットの後に'& 'をつけたので、' .jpg& 'を持っています。この問題の原因は、書き換えを使用すると、新しいURIが再処理されるためです。あなたのケースでは、それは '.jpg'だったので... regexから削除すると動作しますが、gifはどうですか?彼らはまた除外すべきですか? –

4

エラーログレベルを変更してデバッグし、書き換えログを追加します。テストのために、こちらをご覧ください

error_log /var/log/nginx/error.log debug; 
rewrite_log on; 

:何かhttps://gist.github.com/jmervine/8943627 - サンプル設定があり、あなたがテストを自動化することができます。フルログで問題を解決できます。

私はこのような何かを持っている:

2016/04/21 13:02:10 [debug] 7566#7566: *1 http script regex: "^/wiki/([^?]*)(?:\?(.*))?" 
2016/04/21 13:02:10 [notice] 7566#7566: *1 "^/wiki/([^?]*)(?:\?(.*))?" matches "/wiki/File:test.jpg", client: 127.0.0.1, server: , request: "GET /wiki/File:test.jpg HTTP/1.1", host: "localhost" 
2016/04/21 13:02:10 [debug] 7566#7566: *1 http script copy: "/index.php" 
2016/04/21 13:02:10 [debug] 7566#7566: *1 http script args 
2016/04/21 13:02:10 [debug] 7566#7566: *1 http script copy: "title=" 
2016/04/21 13:02:10 [debug] 7566#7566: *1 http script capture: "File:test.jpg" 
2016/04/21 13:02:10 [debug] 7566#7566: *1 http script copy: "&" 
2016/04/21 13:02:10 [debug] 7566#7566: *1 http script capture: "" 
2016/04/21 13:02:10 [debug] 7566#7566: *1 http script regex end 
2016/04/21 13:02:10 [notice] 7566#7566: *1 rewritten data: "/index.php", args: "title=File:test.jpg&", client: 127.0.0.1, server: _, request: "GET /wiki/File:test.jpg HTTP/1.1", host: "localhost" 

は、あなたの正規表現を改善することができますように...私は後で今日より良いものを見つけるしようとするでしょうに見えます。

+0

https://github.com/TeXXaS/nginx-configs - 約束通り - 書き換えをテストするためのサンプルプロジェクトです。 '書き直し^/wiki /([^?]*)(?:\?.*)のように見えますか? /index.php?title=$1 last; 'オリジナルと同じように動作します –

関連する問題