我有两台服务器,需要配置nginx http_image_filter模块。
第一个服务器配置:
server {
listen 80;
server_name image.site.com;
access_log /var/log/nginx/image.site.com-access.log;
error_log /var/log/nginx/image.site.com-error.log;
location / {
proxy_pass http://192.168.1.4;
}
}
在192.168.1.4上的配置是:
server {
listen 80;
server_name image.site.com;
access_log /var/log/nginx/image.site.com-access.log;
error_log /var/log/nginx/image.site.com-error.log;
root /home/zulu/img/RU/;
location ~ "/img/RU/(.*[^0-9])([0-9]+)x([0-9]+).png$" {
set $image $1;
set $width $2;
set $height $3;
image_filter resize $width $height;
}
}
我转到image.site.com/img/RU/image.png
时不起作用我在做什么错了?
答案 0 :(得分:0)
这是正确的配置:
代理
server {
listen 80;
server_name image.site.com;
access_log /var/log/nginx/image.site.com.log;
error_log /var/log/nginx/image.site.com-error.log;
location / {
proxy_pass http://192.168.151.4;
}
proxy_cache images;
proxy_cache_lock on;
proxy_cache_valid 30d;
proxy_cache_use_stale error timeout invalid_header updating;
expires 30d;
}
和图像服务器
server {
listen 80;
server_name image.site.com;
access_log /var/log/nginx/image.site.com.log;
error_log /var/log/nginx/image.site.com-error.log;
root /var/www/files/update/ServiceLogo/;
image_filter_buffer 50M;
location ~ ^/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
image_filter resize $width $height;
alias /var/www/files/update/ServiceLogo/$name;
}
location ~ ^/c/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
image_filter crop $width $height;
alias /var/www/files/update/ServiceLogo/$name;
}
location ~ ^/users/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
image_filter resize $width $height;
alias /var/www/files/update/personDocs/$name;
}
location ~ ^/cusers/(?<width>\d+)x(?<height>\d+)/(?<name>.*)$ {
image_filter crop $width $height;
alias /var/www/files/update/personDocs/$name;
}
}