1. 下载解压nginx,pcre,zlib
wget http://nginx.org/download/nginx-1.11.2.tar.gz tar zxvf nginx-1.11.2.tar.gz wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.bz2 tar jxvf pcre-8.37.tar.bz2 wget http://zlib.net/zlib-1.2.8.tar.gz tar zxvf zlib-1.2.8.tar.gz 
2. 添加nginx水印支持
wget https://codeload.github.com/intaro/nginx-image-filter-watermark/zip/master unzip master cd nginx-image-filter-watermark-master/ cp ngx_http_image_filter_module.c ../nginx-1.11.2/src/http/modules/
3. 编译安装
cd nginx-1.11.2 sudo yum install openssl openssl-devel gd gd-devel ./configure --prefix=/root/programs/nginx --with-http_ssl_module --with-pcre=../pcre-8.37 --with-zlib=../zlib-1.2.8 --with-http_image_filter_module make make install
4.配置文件
user root;
worker_processes 20;
http {
 include mime.types;
 default_type application/octet-stream;
 
 client_max_body_size 10m;
 
 server {
        listen 10000;
        server_name www.xxx.com;
        access_log  logs/xxx.log;
        
        location ~*/img/(\d+):(\d+)/(.*)$ {
             set $resize_width $1;
             set $resize_height $2;
             alias /xxx/xxx/xxx/$3;
             image_filter resize $resize_width $resize_height;
             image_filter crop $resize_width $resize_height;
             image_filter_jpeg_quality 90;
             image_filter_buffer 15M;
         }
         
        location ~*/xxx/(.*)$ {
            alias /xxx/xxx/xxx/$1;
         }
         
        location /xxx/xxx/ {
             root /xxx/xxx/xxx;
             image_filter watermark;
             image_filter_watermark "/xxx/xxx/xxx/watermark.png";
             image_filter_watermark_position bottom-right;
             image_filter_jpeg_quality 95;
             image_filter_buffer 15M;
         }
         
        error_page  404              /notfound.jpg;
		location /notfound.jpg {
			alias /xxx/xxx/xxx/notfound.jpg; 
		}
		
		location /xxx/ {
			add_header Access-Control-Allow-Origin *;
			add_header Access-Control-Allow-Headers X-Requested-With;  
			add_header Access-Control-Allow-Methods GET,POST,OPTIONS;  
			proxy_pass http://127.0.0.1:9001/;
        }
		
		location /xxx/ {
			proxy_pass http://127.0.0.1:9002/;
		}
     
    }
    
    server {
        ....
    }
    
    server {
        ....
    }
} 
负载均衡 nginx upstream
	
No Leanote account? Sign up now.