我收到以下錯誤噸,所有的錯誤都指向圖像,實際上並不存在的位置,錯誤正在給出,他們在Nginx重寫從Apache轉換而來。Nginx:重寫規則不適用於圖像
所有在Apache中工作正常,只是因爲我切換到Nginx的圖像不顯示,所有其他重寫規則,只是網址都工作正常,只有圖像打破?!
錯誤
2017/04/02 23:15:16 [error] 27629#0: *6 open() "/var/www/html/media/images/blog/10_1.png" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: www.website.com, request: "GET /media/images/blog/10_1.png HTTP/1.1", host: "www.website.com", referrer: "https://www.website.com/blog/"
阿帕奇重寫規則:
## Images
RewriteRule ^media/images/([^/]+)/([^/]+)_([^-]+)_([^-]+)\.png$ /img.php?prefix=$1&refId=$2&thumb=$3&iid=$4 [L]
RewriteRule ^media/images/([^/]+)/([^/]+)_([^-]+)\.png$ /img.php?prefix=$1&refId=$2&thumb=$3 [L]
## Blog Pages
RewriteRule ^blog/$ /?action=blog [L]
RewriteRule ^blog/([a-zA-Z0-9-]+)/$ /?action=blog&category=$1 [L]
RewriteRule ^blog/([a-zA-Z0-9-]+)/([0-9]+)-([a-zA-Z0-9-]+)/$ /?action=blog&category=$1&id=$2&title=$3 [L]
Nginx的重寫規則
location /media {
rewrite ^/media/images/([^/]+)/([^/]+)_([^-]+)_([^-]+)\.png$ /img.php?prefix=$1&refId=$2&thumb=$3&iid=$4 last;
rewrite ^/media/images/([^/]+)/([^/]+)_([^-]+)\.png$ /img.php?prefix=$1&refId=$2&thumb=$3 last;
}
location /blog {
rewrite ^/blog/$ /?action=blog last;
rewrite ^/blog/([a-zA-Z0-9-]+)/$ /?action=blog&category=$1 last;
rewrite ^/blog/([a-zA-Z0-9-]+)/([0-9]+)-([a-zA-Z0-9-]+)/$ /?action=blog&category=$1&id=$2&title=$3 last;
}
修復
location ^~ /media/images {
rewrite ^/media/images/([^/]+)/([^/]+)_([^-]+)_([^-]+)\.png$ /img.php?prefix=$1&refId=$2&thumb=$3&iid=$4 last;
rewrite ^/media/images/([^/]+)/([^/]+)_([^-]+)\.png$ /img.php?prefix=$1&refId=$2&thumb=$3 last;
}
location /blog/ {
rewrite ^/blog/$ /?action=blog last;
rewrite ^/blog/([a-zA-Z0-9-]+)/$ /?action=blog&category=$1 last;
rewrite ^/blog/([a-zA-Z0-9-]+)/([0-9]+)-([a-zA-Z0-9-]+)/$ /?action=blog&category=$1&id=$2&title=$3 last;
}
將位置前綴'location/media /'加上'/'和文件名的精確正則表達式,例如'^/media/images /([^ /] +)/(\ d +)_(\ d +)\。 png $' – Deadooshka