Last active
March 14, 2017 07:56
-
-
Save songlipeng2003/173c9b3e959ce628540a3360f2d905c2 to your computer and use it in GitHub Desktop.
nginx image_filter resize config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name www.test.com; | |
return 301 https://$server_name$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name www.test.com; | |
charset utf-8; | |
client_max_body_size 100M; | |
#access_log logs/host.access.log main; | |
root /var/www/test/current/web/; | |
index index.html index.htm index.php; | |
ssl_certificate /etc/letsencrypt/live/api.test.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/api.test.com/privkey.pem; | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { | |
try_files $uri =404; | |
} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location ~ \.php$ { | |
root /var/www/test/current/web; | |
#fastcgi_pass 127.0.0.1:9000; | |
fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; | |
} | |
location ~ /\.(ht|svn|git) { | |
deny all; | |
} | |
location /.well-known/acme-challenge/ { | |
alias /var/www/acme-challenge/.well-known/acme-challenge/; | |
} | |
# 缩略图 | |
location ~* /uploads/(.+)\.(jpg|png|jpeg|gif)!(\w)_(\d+)\*(\d+)$ { | |
set $filename /uploads/$1.$2; | |
if (-f $filename) { | |
break; | |
} | |
if (!-f $document_root/$filename) { | |
return 404; | |
} | |
# 根据 URL 地址 ! 后面的图片版本来准备好需要的参数(宽度、高度、裁剪或缩放) | |
set $img_version $3; | |
set $img_type resize; | |
set $img_w $4; | |
set $img_h $5; | |
if ($img_version = 'c') { | |
set $img_type crop; | |
} | |
rewrite ^ /_$img_type; | |
} | |
# 缩放图片的处理 | |
location /_resize { | |
alias /var/www/test/current/web$filename; | |
image_filter resize $img_w $img_h; | |
image_filter_jpeg_quality 95; | |
image_filter_buffer 20M; | |
image_filter_interlace on; | |
} | |
# 裁剪图片的处理 | |
location /_crop { | |
alias /var/www/test/current/web$filename; | |
image_filter crop $img_w $img_h; | |
image_filter_jpeg_quality 95; | |
image_filter_buffer 20M; | |
image_filter_interlace on; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment