Centos搭建Nginx图片缓存服务器

搭建Nginx图片缓存服务器
[root@localhost ~]# yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl*
[root@localhost ~]# useradd -M -u 40 -s /sbin/nologin  nginx
[root@localhost ~]# tar zxvf ng
nginx-1.9.1.tar.gz              nginx-upload-module-2.2.tar.gz  ngx_cache_purge-2.3.tar.gz
[root@localhost ~]# tar zxvf nginx-1.9.1.tar.gz -C /usr/src/
[root@localhost ~]# tar zxvf nginx-upload-module-2.2.tar.gz -C /usr/src/
[root@localhost ~]# tar zxvf ngx_cache_purge-2.3.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.9.1/
[root@localhost nginx-1.9.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --add-module=/usr/src/ngx_cache_purge-2.3 --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --add-module=/usr/src/nginx-upload-module-2.2
[root@localhost nginx-1.9.1]# make -j4
[root@localhost nginx-1.9.1]# make install
[root@localhost nginx-1.9.1]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost nginx-1.9.1]# nginx
查看配置文件:
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
#user  nobody;
user  nginx;
worker_processes  4;


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


pid        logs/nginx.pid;


worker_rlimit_nofile 65535;


events {
    use epoll;
    worker_connections  65535;
}


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


 charset utf-8;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 2k;
    large_client_header_buffers 4 4k;
    client_max_body_size 8m;


server_tokens off;
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;


fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 4k;
    fastcgi_buffers 8 4k;
    fastcgi_busy_buffers_size 8k;
fastcgi_temp_file_write_size 8k;


open_file_cache max=204800 inactive=20s;
    open_file_cache_min_uses 1;
    open_file_cache_valid 30s;


 gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/webp image/jpeg image/gif image/png;
    gzip_vary on;


 client_body_buffer_size  512k;
  proxy_connect_timeout    5;
  proxy_read_timeout       60;
  proxy_send_timeout       5;
  proxy_buffer_size        16k;
  proxy_buffers            4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;
  proxy_temp_path   /data/proxy_temp_dir;
#设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为5GB。
#proxy_cache_path和proxy_temp_path设置的目录需要在同一分区,因为它们之间是硬链接的关系。
  proxy_cache_path  /data/proxy_cache_dir  levels=1:2   keys_zone=cache_one:300m inactive=1d max_size=5g;


keepalive_timeout  60;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;


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


   upstream webservers{
        server 127.0.0.1:8100;
       }
include /usr/local/qxg/nginx/conf.d/*.conf;
}
[root@localhost ~]# vim /usr/local/qxg/nginx/conf.d/image.conf
server
    {
            listen  80;
            server_name  192.168.40.2;
            index index.php index.html index.htm;
            root   /data/imgerserver/;
            autoindex on;
            autoindex_localtime on;
            autoindex_exact_size off;
            access_log /data/nginx/logs/soft.log  combined;
            error_log  /data/nginx/logs/soft-error.log debug;


            
            location ~ .*\.(webp|gif|jpg|jpeg|png|bmp|swf|ico)?$
            {
                expires 30d;
                proxy_cache cache_one;
                proxy_cache_valid 200 304 301 302 10d;
                proxy_cache_valid any 1d;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_cache_key $host$uri$is_args$args;
                proxy_pass http://123.56.86.137:8010;
            } 


            location /nginx-status {
                stub_status on;
                access_log on;
                allow 127.0.0.1;
                allow 10.44.38.122; 
                deny all;
             }       


            location ~ .*\.(js|css)?$
            {
                expires      24h;
            }


}
server {
        listen 8010;
        server_name 192.168.40.2;
        root /data/imgerserver/;
#           autoindex on;
            autoindex_localtime on;
            autoindex_exact_size off;
            access_log /data/nginx/logs/image-access.log  combined;
            error_log  /data/nginx/logs/image-error.log debug;


       location ~ .*\.(webp|gif|jpg|jpeg|png|bmp|swf|ico)$
            {
                expires 30d;
            }


            location ~ .*\.(js|css)?$
            {
                expires      24h;
            }
#proxy_cache cache_one;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值