# cd /usr/local/nginx/conf/
# vim proxy.conf
*********************************************************************
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
#Nginx cache
client_body_temp_path client_body 1 2;
proxy_temp_path proxy_temp 1 2;
#client_body_temp_path /tmpfs/client_body_temp 1 2;
#proxy_temp_path /tmpfs/proxy_temp 1 2;
#fastcgi_temp_path /tmpfs/fastcgi_temp 1 2;
*********************************************************************
1.6建立Ningx虚拟主机目录
# mkdir -p /usr/local/nginx/conf/vhost
# mkdir /home/www
# chmod 755 -R /home/www
# chown -R www.www /home/www/
# chown www /usr/local/nginx/conf/
1.7启动、关闭Nginx
# cp /usr/local/nginx/sbin/nginx /etc/init.d/nginx
# /etc/init.d/nginx #启动Nginx
# /etc/init.d/nginx -s reload #重启Nginx
# /etc/init.d/nginx -s stop #关闭Nginx
1.8 Nginx启动脚本
# vim /etc/init.d/nginx
********************************************************************
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on RHEL. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/RedHat run: 'chkconfig --add nginx'
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
********************************************************************
# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on
