我收到以下错误吨,所有的错误都指向图像,实际上并不存在的位置,错误正在给出,他们在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