2017-04-03 38 views
1

我收到以下錯誤噸,所有的錯誤都指向圖像,實際上並不存在的位置,錯誤正在給出,他們在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; 
} 
+0

將位置前綴'location/media /'加上'/'和文件名的精確正則表達式,例如'^/media/images /([^ /] +)/(\ d +)_(\ d +)\。 png $' – Deadooshka

回答

1

你可能在你的配置文件,它的任何URI與.png比賽結束衝突location塊。

通過添加^~修飾符,可以使location /media塊的優先級高於正則表達式位置塊。

例如:

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; 
} 

參見this document更多。

+0

謝謝,您指出我的方向正確,我已經用適合我的修復程序更新了我的問題。 – llanato