#關閉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