开心六月综合激情婷婷|欧美精品成人动漫二区|国产中文字幕综合色|亚洲人在线成视频

    1. 
      
        <b id="zqfy3"><legend id="zqfy3"><fieldset id="zqfy3"></fieldset></legend></b>
          <ul id="zqfy3"></ul>
          <blockquote id="zqfy3"><strong id="zqfy3"><dfn id="zqfy3"></dfn></strong></blockquote>
          <blockquote id="zqfy3"><legend id="zqfy3"></legend></blockquote>
          打開APP
          userphoto
          未登錄

          開通VIP,暢享免費電子書等14項超值服

          開通VIP
          nginx+lua_nginx+GraphicsMagick生成實時縮略圖

          暫做筆記,帶后續(xù)驗證通過后,再補充 1、2、3 步。

          一、安裝 lua

             首先確認是否安裝 readline

            yum -y install readline-devel ncurses-devel

           進入頁面:http://www.lua.org/download.html

          wget http://www.lua.org/ftp/lua-5.3.1.tar.gz  tar zxvf lua-5.3.1.tar.gz #進入解壓目錄make linux && make install

           

          wget http://luajit.org/download/LuaJIT-2.0.4.tar.gztar zxvf LuaJIT-2.0.4.tar.gz cd LuaJIT-2.0.4make && make install

           

          ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2export LUAJIT_LIB=/usr/local/libexport LUAJIT_INC=/usr/local/include/luajit-2.0/

           

          二、安裝 GraphicsMagick

             進入頁面:http://www.graphicsmagick.org/1.3/download.html

          tar zxvf GraphicsMagick-1.3.21.tar.gzcd GraphicsMagick-1.3.21./configure  --prefix=/usr/local/graphicsmagick
          make && make install

          #驗證

             /usr/local/graphicsmagick/bin/gm version

          三、安裝nginx

            進入頁面:http://tengine.taobao.org/opensource_cn.html

           

          ./configure --prefix=/usr/local/nginx             --dso-path=/usr/local/nginx/modules             --with-http_realip_module             --with-http_gzip_static_module             --with-http_stub_status_module             --with-http_concat_module             --with-http_lua_module             --with-pcre=/usr/local/src/pcre-8.37            --with-zlib=/usr/local/src/zlib-1.2.8            --with-openssl=/usr/local/src/openssl-1.0.0s            --http-proxy-temp-path=/var/tmp/nginx/proxy_temp             --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp             --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp             --http-scgi-temp-path=/var/tmp/nginx/cgi_temp             --http-client-body-temp-path=/var/tmp/nginx/client_body_temp             --http-log-path=/var/log/nginx/access.log             --error-log-path=/var/log/nginx/error.log            --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"make && make install#啟動nginx#測試配置文件  /usr/local/nginx/sbin/nginx -t#啟動/usr/local/nginx/sbin/nginx 

           

           設置開機啟動

            

          vi /etc/rc.d/init.d/nginx 

           

            

          #!/bin/bash# Tengine Startup script# processname: nginx# chkconfig: - 85 15# description: nginx is a World Wide Web server. It is used to serve# pidfile: /var/run/nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pidRETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start() {if [ -e $nginx_pid ];thenecho "tengine already running...."exit 1fiecho -n $"Starting $prog: "daemon $nginxd -c ${nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/nginxreturn $RETVAL}# Stop nginx daemons functions.stop() {echo -n $"Stopping $prog: "killproc $nginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid}reload() {echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`killproc $nginxd -HUPRETVAL=$?echo}# See how we were called.case "$1" instart)start;;stop)stop;;reload)reload;;restart)stopstart;;status)status $progRETVAL=$?;;*)echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit 1esacexit $RETVAL

          保存退出

          chmod 775 /etc/rc.d/init.d/nginx   #賦予文件執(zhí)行權限chkconfig  --level 012345 nginx on   #設置開機啟動service nginx start

           

          四、配置 nginx

            nginx.conf

          http   {        lua_package_path '/usr/local/openresty/nginx/lua/?.lua;;';                server {                listen       80;                server_name  img.rhythmk.org;                root  /home/wwwroot/static/image;                                #對類似_100x100.gif/jpg/png/jpeg進行縮略圖處理                location ~* _([0-9]+)x([0-9]+)\.(gif|jpg|png|jpeg)$ {                 #匹配文件名規(guī)則                        root  /home/wwwroot/static/image;                             #站點根目錄                        set $image_root /home/wwwroot/static/image;                   #圖片目錄                        set $thumbnail_root /home/wwwroot/static/thumbnail;           #縮略圖存放目錄                        #如果縮略圖文件存在,直接返回                        set $file $thumbnail_root$uri;                        if (-f $file) {                                rewrite ^/(.*)$ /thumbnail/$1 last;                        }                        #如果縮略圖文件不存在,則應用縮略圖模塊處理                        if (!-f $file) {                                rewrite_by_lua_file lua/thumbnail.lua;                        }                }         }      #include conf/*.conf;}

          lua/thumbnail.lua

              local index = string.find(ngx.var.uri, "([0-9]+)x([0-9]+)");      local originalUri = string.sub(ngx.var.uri, 0, index-2);      local area = string.sub(ngx.var.uri, index);      index = string.find(area, "([.])");      area = string.sub(area, 0, index-1);        local image_sizes = {"80x80", "800x600", "40x40"};      function table.contains(table, element)         for _, value in pairs(table) do            if value == element then               return true            end         end         return false      end        if table.contains(image_sizes, area) then          local command = "gm convert " .. ngx.var.image_root .. originalUri .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. area .. " " .. ngx.var.file;          os.execute(command);          ngx.req.set_uri(ngx.var.uri, true);      else          ngx.exit(404);      end;  

           

          本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現有害或侵權內容,請點擊舉報。
          打開APP,閱讀全文并永久保存 查看更多類似文章
          猜你喜歡
          類似文章
          fastdfs支持縮略圖
          Nginx+Naxsi部署專業(yè)級web應用防火墻
          手動編譯 Nginx 并安裝 VeryNginx
          第一章 安裝Nginx+Lua開發(fā)環(huán)境
          OpenResty + ngx_lua_waf使用
          Nginx安裝lua
          更多類似文章 >>
          生活服務
          分享 收藏 導長圖 關注 下載文章
          綁定賬號成功
          后續(xù)可登錄賬號暢享VIP特權!
          如果VIP功能使用有故障,
          可點擊這里聯(lián)系客服!

          聯(lián)系客服