配置文件位由编译参数--conf-path指定,这里位于/etc/nginx/目录下. 1. http服务配置文件: user www www; worker_processes 5; error_log /var/nginx/logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /var/nginx/nginx.pid; events { use epoll; worker_connections 1024; } http { include mime.types; default_type application/octet-stream; root /var/www/htdocs/; 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/nginx/logs/access.log main; sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; server { listen 80; server_name localhost; #charset koi8-r; access_log /var/nginx/logs/host.access.log main; location / { root /var/www/htdocs/; index index.html index.htm index.php; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/htdocs; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:10005; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/htdocs/$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } } 2. 反向代理配置文件 user www www; worker_processes 10; error_log /var/nginx/logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /var/nginx/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; keepalive_timeout 120; tcp_nodelay on; upstream localhost{ ip_hash; server 10.40.0.46; server 10.40.0.47; server 10.40.0.48; } upstream blog.s135.com { server 192.168.1.7:8080; server 192.168.1.7:8081; server 192.168.1.7:8082; } server { listen 80; server_name localhost; location / { proxy_pass http://localhost; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } log_format localhost '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/nginx/logs/www.log localhost; } } 3. nginx系统启动服务文件 #!/bin/bash # nginx Startup script for the Nginx HTTP Server # this script create it by jackbillow at 2007.10.15. # it is v.0.0.2 version. # if you find any errors on this scripts,please contact jackbillow. # and send mail to jackbillow at gmail dot com. # # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/nginx/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/sbin/nginx nginx_config=/etc/nginx/nginx.conf nginx_pid=/var/nginx/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 /var/run/nginx.pid } # reload nginx service functions. 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 4. spawn-fcgi系统启动服务文件 #!/bin/sh # # chkconfig: - 85 15 # description: PHP Fast-CGI # processname: PHP Fast-CGI # pidfile: /var/run/php-cgi.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 SPAWNFCGI="/usr/local/bin/spawn-fcgi" FCGIPROGRAM="/opt/local/php-5.2.10/bin/php-cgi" FCGIPID="/var/run/php-cgi.pid" FCGIPORT="10005" FCGIADDR="127.0.0.1" FCGIUSER="www" FCGIGROUP="www" PHP_FCGI_CHILDREN=200 ## maximum number of requests a single PHP process can serve before it is restarted PHP_FCGI_MAX_REQUESTS=1000 # lockfile=/var/lock/subsys/php-cgi prog=$(basename ${FCGIPROGRAM}) start() { echo -n $"Starting $prog: " daemon $SPAWNFCGI -f "${FCGIPROGRAM}" -a $FCGIADDR -p $FCGIPORT -C $PHP_FCGI_CHILDREN -u $FCGIUSER -g $FCGIGROUP -P $FCGIPID >> /dev/null 2>&1 retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { stop echo -ne "Restart...\n" sleep 3 start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart}" RETVAL=1 esac (责任编辑:IT) |