• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

nginxlua处理图片

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
user apache apache;
worker_processes 4;
worker_rlimit_nofile 100000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
use epoll;
multi_accept on;
worker_connections 51200;
}

# load modules compiled as Dynamic Shared Object (DSO)
#
dso {
# load ngx_http_fastcgi_module.so;
# load ngx_http_rewrite_module.so;
}

http
{
server_tokens off;
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 20;

server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_body_buffer_size 512k;
client_max_body_size 20m;
gzip on;
gzip_disable "msie6";
gzip_min_length 1k;
gzip_buffers 16 64k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript;
gzip_vary on;

lua_package_path '/usr/local/tengine/lua/?.lua;;';

upstream tomcat_server {
ip_hash;
server 172.16.151.112:6080 ;
server 172.16.151.113:6080 ;
# server 172.16.151.235 max_fails=2 fail_timeout=30s;
}


server {
listen 80;
server_name image0.lovebuy.com.cn;
# root /usr/html/lovebuy;


location = / {
root /usr/html/lovebuy/html;
index index.html;
}

location ~ ^/index.html$ {
root /usr/html/lovebuy/html;
}

location ^~ /subject/ {
root /usr/html/lovebuy/html;
}

# location ~ ^/goods_(\d\d\d).html$ {
#
# if (-f $request_filename) {
# root /usr/html/lovebuy/html;
# rewrite ^/goods_(\d\d).html$ /page0$1/goods_0$1.html break;
# rewrite ^/goods_(\d+).html$ /page$1/goods_$1.html break;
# }
#
# if (!-f $request_filename) { 
# # rewrite ^/goods_(\d+).html http://www.lovebuy.com.cn/goods_3784.html permanent;
# rewrite ^/goods_(\d+).html http://172.16.151.112:6080/goods_$1.htm permanent;
# }
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_pass http://tomcat_server;
# }


location ~ ^/goods_(.*)(\d\d\d).html$ {

root /usr/html/lovebuy/html/page$2/;

if (-f $request_filename) {
rewrite ^/goods_(.*)(\d\d\d).html$ /goods_$1$2.html break;
}

if (!-f $request_filename) {
rewrite ^/goods_(\d+).html http://$host/goods_$1.htm ;
# proxy_pass http://tomcat_server ;
}
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_pass http://tomcat_server;
}

# location ~ ^/goods_(.*)(\d\d\d).html$ {
#
# root /usr/html/lovebuy/html;
# rewrite ^/goods_(.*)(\d\d\d).html$ /page$2/goods_$1$2.html break;
# }


#/thumbnail目录下的图片请求不经过缩略图模块
location ^~ /thumbnail/ {
root /usr/html/lovebuy/upload;

}


location /lua {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}

######################################################### 
#对类似_100x100.gif/jpg/png/jpeg进行缩略图处理
location ~* _([0-9]+)x([0-9]+)\.(gif|jpg|png|jpeg)$ { #匹配文件名规则
# location ^~ /photo/ { #匹配文件名规则
rewrite ^/(upload/)(.*)$ /$2 last;
root /usr/html/lovebuy/upload; #点根目录
lua_code_cache off;
set $image_root /usr/html/lovebuy/upload; #图片目录
set $thumbnail_root /usr/html/lovebuy/upload/thumbnail; #缩略图存放目录
#果缩略图文件存在,直接返回
set $file $thumbnail_root$uri;
if (-f $file) {
rewrite ^/(.*)$ /thumbnail/$1 last;
}

#果缩略图文件不存在,则应用缩略图模块处理
if (!-f $file) {
rewrite_by_lua_file /usr/local/tengine/lua/thumbnail.lua;
# rewrite_by_lua '
# local command = "/usr/local/GraphicsMagick/bin/gm convert /usr/local/tengine/html/image/photo/2m.jpg /usr/local/tengine/html/image/photo/2m_300x300.jpg" ;
# os.execute(command);

# '; 
}

}
location /nginx-status {
stub_status on;
access_log off;
#加入访问限制
#allow 60.195.252.106;
allow 172.16.151.83;
#deny all;
}
##################缓存配置###############################3
location ~ \.(gif|jpg|jpeg|png|bmp|ico)$ {
root /usr/html/lovebuy/;
expires 1d;

}

location ^~ /resources/ {
root /usr/html/lovebuy/;
expires 30d;

}

 

 

 

###################缓存配置-end##########################
location / {
concat on; #开启concat模块
root /usr/html/lovebuy/;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Lua脚本编写一个简单日历记事本发布时间:2022-07-22
下一篇:
lua pl库 file.copy异常记录发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap