NGINX部署图片服务器

#关闭SELINUX

setenforce 0

vi /etc/sysconfig/selinux

SELINUX=disabled

#关闭防火墙

service iptables stop

chkconfig --level 2345 iptables off

#安装编译包
yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd  kernel keyutils  patch perl

#下载nginx软件
cd /opt
wget http://nginx.org/download/nginx-1.4.4.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz

 wget http://www.openssl.org/source/openssl-1.0.1f.tar.gz

#安装nginx软件
tar zxvf nginx-1.4.4.tar.gz
tar zxvf pcre-8.34.tar.gz
tar zxvf ngx_cache_purge-2.1.tar.gz

tar xvzf  openssl-1.0.1f.tar.gz
cd pcre-8.34
./configure  --prefix=/usr/local/pcre
make
make install

cd ../nginx-1.4.4
./configure --prefix=/usr/local/nginx  --user=www --group=www  --with-http_stub_status_module --with-openssl=/opt/openssl-1.0.1f --with-http_ssl_module --with-pcre=/opt/pcre-8.34 --add-module=/opt/ngx_cache_purge-2.1

make
make install

chown www.www -R //data/var/www/html/bestbuy #设置网站图片目录属主

chmod 700 -R /data/var/www/html/bestbuy #设置网站图片目录权限

vi /etc/rc.d/init.d/nginx  #编辑启动脚本
=======================================================

# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve


nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="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 ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        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 -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL
=======================================================

vi /usr/local/nginx/conf/nginx.conf  #编辑nginx配置
=====================================================================
user              www;
worker_processes  16;

error_log  /var/log/nginx/error.log;

pid        /usr/local/nginx/logs/nginx.pid;


events {
    use epoll;
    worker_connections  65535;
}


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  /var/log/nginx/access.log  main;

    charset  utf-8;         
    server_names_hash_bucket_size 128;  
    client_header_buffer_size 32k;  
    large_client_header_buffers 4 32k;  
    client_max_body_size 300m;         
    sendfile on;  
    tcp_nopush     on;
    keepalive_timeout  65;

    gzip  on;
    gzip_min_length  1k;  
    gzip_buffers 4 16k;  
    gzip_http_version 1.1;  
    gzip_comp_level 2;  
    gzip_types text/plain application/x-javascript text/css application/xml;  
    gzip_vary on;
   
    proxy_temp_path /data/var/www/html/bestbuy/media/images_temp;
    Proxy_cache_path /data/var/www/html/bestbuy/media/images_cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;

    log_format cache '***$time_local '  '***$upstream_cache_status '  '***Cache-Control: $upstream_http_cache_control ' '***Expires: $upstream_http_expires ' '***"$request" ($status) ' '***"$http_user_agent" ';

    server {
        listen 8081;
        server_name  192.168.1.139;
        location / {
                        proxy_cache cache_one;
                        proxy_cache_valid  200 304 12h;
                        proxy_cache_key $host$uri$is_args$args;
                        proxy_set_header Host  $host;
                        proxy_set_header X-Forwarded-For  $remote_addr;
                        proxy_pass http://192.168.1.139:8080;
                        access_log  /var/log/nginx/cache.log cache;
                        expires      1d;
        }

        location ~ /purge(/.*) {
                    allow       127.0.0.1;
                    allow       192.168.0.0/16;
                    deny        all;
                    proxy_cache_purge    cache_one   $host$1$is_args$args;
        }

        location ~ .*\.(php|jsp|cgi)?$ {
                        proxy_set_header Host  $host;
                        proxy_set_header X-Forwarded-For  $remote_addr;
                        proxy_pass http://192.168.1.139:8080;
        }
        access_log  off;
    }

    server{
        listen 8080;
        server_name 192.168.1.139;   
        location / {
            root /data/var/www/html/bestbuy;
        }
        access_log off;
    }
}
}
=====================================================================

chmod 775 /etc/rc.d/init.d/nginx  #设置执行权限
chkconfig nginx on   #设置开机自启动
service nginx restart #重启nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值