Install Thumbor Centos and Nginx aliasing url

  1. Update System & install development tools
    yum update -y ; yum groupinstall "development tools" -y
  2. Install Package
    yum install -y epel-release deltarpm openssl-devel sqlite-devel bzip2-devel
  3. Install & config nginx
    yum install -y nginx ; /sbin/chkconfig nginx on;
    create file thumbor.conf
    nano /etc/nginx/conf.d/thumbor.conf
    upstream thumbor  {
        server 127.0.0.1:8000;
        server 127.0.0.1:8001;
        server 127.0.0.1:8002;
        server 127.0.0.1:8003;
    }
    
    server {
        listen       80;
        server_name  <INSERT YOUR DOMAIN NAME>;
        client_max_body_size 10M;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://thumbor;
            proxy_redirect off;
        }
    }
  4. Install Thumbor Lib
    yum install libjpeg-turbo-devel.x86_64 libjpeg-turbo-utils.x86_64 libtiff-devel.x86_64 libpng-devel.x86_64 pngcrush jasper-devel.x86_64 libwebp-devel.x86_64 python-pip -y
    pip install pycurl numpy
    pip install thumbor==4.12.2
    
  5. create file optimizer plugins pngcrush for png
    nano /usr/local/lib64/python2.7/site-packages/thumbor/optimizers/pngcrush.py
    paste this
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    # thumbor imaging service
    # https://github.com/thumbor/thumbor/wiki
    
    # Licensed under the MIT license:
    # http://www.opensource.org/licenses/mit-license
    
    
    import os
    import subprocess
    
    from thumbor.optimizers import BaseOptimizer
    from thumbor.utils import logger
    
    
    class Optimizer(BaseOptimizer):
        def __init__(self, context):
            super(Optimizer, self).__init__(context)
    
            self.runnable = True
            self.pngcrush_path = self.context.config.PNGCRUSH_PATH
            if not (os.path.isfile(self.pngcrush_path) and os.access(self.pngcrush_path, os.X_OK)):
                logger.error("ERROR pngcrush path '{0}' is not accessible".format(self.pngcrush_path))
                self.runnable = False
    
        def should_run(self, image_extension, buffer):
            return 'png' in image_extension and self.runnable
    
        def optimize(self, buffer, input_file, output_file):
            command = '%s -reduce -q %s %s ' % (
                self.pngcrush_path,
                input_file,
                output_file,
            )
            with open(os.devnull) as null:
                subprocess.call(command, shell=True, stdin=null)
    Generate Config file
    thumbor-config > /etc/thumbor.conf
    change LOADER in file thumbor.conf for load file image from server
    LOADER = 'thumbor.loaders.file_loader'
    
  6. enable Optimizer in thumbor.conf
    OPTIMIZERS = [
        'thumbor.optimizers.jpegtran',
        'thumbor.optimizers.pngcrush',
    ]
    
    JPEGTRAN_PATH = '/usr/bin/jpegtran'
    PNGCRUSH_PATH = '/usr/bin/pngcrush'
  7. Install & configure supervisor
    easy_install supervisor
    create file /etc/init.d/supervisord
    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides:          supervisord
    # Required-Start:    $remote_fs
    # Required-Stop:     $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Supervisor init script
    # Description:       Supervisor init script    
    ### END INIT INFO
    
    # Supervisord auto-start
    #
    # description: Auto-starts supervisord
    # processname: supervisord
    # pidfile: /var/run/supervisord.pid
    
    SUPERVISORD=/usr/local/bin/supervisord
    SUPERVISORCTL=/usr/local/bin/supervisorctl
    ARGS="-c /etc/supervisord.conf"
    
    case $1 in
    start)
            echo -n "Starting supervisord: "
            $SUPERVISORD $ARGS
            echo
            ;;
    stop)
            echo -n "Stopping supervisord: "
            $SUPERVISORCTL shutdown
            echo
            ;;
    restart)
            echo -n "Stopping supervisord: "
            $SUPERVISORCTL shutdown
            echo
            echo -n "Starting supervisord: "
            $SUPERVISORD $ARGS
            echo
            ;;
    esac
    
    create file /etc/supervisord.conf and paste
    [unix_http_server]
    file=/tmp/supervisor.sock   ; (the path to the socket file)
    
    [supervisord]
    logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)  
    logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)  
    logfile_backups=10           ; (num of main logfile rotation backups;default 10)  
    loglevel=info                ; (log level;default info; others: debug,warn,trace)  
    pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)  
    nodaemon=false               ; (start in foreground if true;default false)  
    minfds=1024                  ; (min. avail startup file descriptors;default 1024)  
    minprocs=200                 ; (min. avail process descriptors;default 200)
    
    ; the below section must remain in the config file for RPC
    ; (supervisorctl/web interface) to work, additional interfaces may be
    ; added by defining them in separate rpcinterface: sections
    [rpcinterface:supervisor]
    supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
    
    [supervisorctl]
    serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
    
    [program:thumbor]
    ; The following command uses a different thumbor config file for each
    ; processes, however we want the same setup for each so that isn't necessary
    ; command=thumbor --ip=127.0.0.1 --port=800%(process_num)s --conf=/etc/thumbor800%(process_num)s.conf
    ; Instead we'll use this command to use just the one conf file
    command=/usr/local/bin/thumbor --ip=127.0.0.1 --port=800%(process_num)s --conf=/etc/thumbor.conf  
    process_name=thumbor800%(process_num)s  
    numprocs=4  
    autostart=true  
    autorestart=true  
    startretries=3  
    stopsignal=TERM  
    ; Output logs for each of our processes
    stdout_logfile=/var/log/thumbor.stdout.log  
    stdout_logfile_maxbytes=1MB  
    stdout_logfile_backups=10  
    stderr_logfile=/var/log/thumbor.stderr.log  
    stderr_logfile_maxbytes=1MB  
    stderr_logfile_backups=10
    
    start supervisord and nginx
    chmod +x supervisord ; /etc/init.d/supervisord start; /etc/init.d/nginx start
  8. optional for custom or change unsafe url add in nginx thumbor configuration
      location ~* /thumb/(.*)/(.*\.(jpg|jpeg|png|gif|JPG))$ {

            proxy_pass http://localhost:8000/unsafe/$1/$2;
        }
     change url http://localhost:8000/unsafe/300x300/file.jpg to
    http://localhost:8000/thumb/300x300/file.jpg

    complate installation in here source

    thank you

Comments

  1. hello dear when i follow the your blog for configution thumbor.
    then i access the url is showing default home page of nginx.

    ReplyDelete

Post a Comment

Popular Posts