fastdfs縮略圖配置


在存儲服務上操作(storge)

1.安裝依賴(st-01      st-02)

命令:[root@storage01 ~]# yum install -y pcre pcre-devel openssl openssl-devel gd-devel

命令:[root@storage02 ~]#yum install -y pcre pcre-devel openssl openssl-devel gd-devel

 

2.殺掉nginx進程后編譯nginx(以st-01為例)

命令:[root@storage01 ~]# ps aux | grep nginx

命令:[root@storage01 ~]# kill -9 6462

 

3.重新編譯nginx,添加模塊

命令:[root@storage01 ~]# cd /myself_settings/nginx-1.7.8

命令:[root@storage01 nginx-1.7.8]# ./configure --prefix=/usr/local/nginx --with-http_image_filter_module --add-module=/myself_settings/fastdfs-nginx-module/src

命令:[root@storage01 nginx-1.7.8]# make && make install

 

4.配置nginx解析

命令:[root@storage01 nginx-1.7.8]# vim /usr/local/nginx/conf/nginx.conf

將以下配置文件拷貝進去


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
##

        location ~ group[1-3]/M00/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png) {           #這段往下為生成縮略圖的配置
            root /opt/fastdfs_storage_data/data;
            ngx_fastdfs_module;
            set $w $2;
            set $h $3;


            if ($w != "0") {
                rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break;
            }

            if ($h != "0") {
                rewrite group1/M00(.+)_(\d+)x(\d+)\.(jpg|gif|png)$ group1/M00$1.$4 break;
            }

            image_filter resize $w $h;

            image_filter_buffer 2M;

            try_files group[1-3]/M00$1.$4 $1.jpg;
      }
##
        location ~/group[1-3]/M00{
               root /opt/fastdfs_storage_data/data;
                 ngx_fastdfs_module;
          }



        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        # location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

命令:[root@storage02 nginx-1.7.8]# /usr/local/nginx/sbin/nginx                #然后重啟文件

注意:有多少存儲服務器(storage)都要配置,否則會報404

 

5.測試

將一張圖片放入/root下

命令:[root@storage01 ~]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/20200107204.png

 

 

 

打開瀏覽器輸入http://192.168.175.10:8080/group1/M00/00/00/wKivCl4VntWAQjOrAAEpWNULvG4895_big.png

如下圖:

 

 

 

上面的截圖是原版,我們已經做完了縮略圖,所以我們可以設置圖片的規格大小

同樣在瀏覽器上打開,前面路徑不變,后面添加規格大小  

注意:將后綴big刪除換成規格大小,我調成200x200的, 中間的“x” 是小寫字母x  不是乘號!

輸入:http://192.168.175.10:8080/group1/M00/00/00/wKivCl4VntWAQjOrAAEpWNULvG4895_200x200.png

如下圖:

 

這樣FastDFS圖片服務器的縮略圖配置就做完了

 

 

總結:。。。。。。。。。此處省略一萬字


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM