四、配置nginx为系统服务
| vi /etc/init.d/nginx #!/bin/bash # nginx Startup script for the Nginx HTTP Server # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse # proxy and IMAP/POP3 proxy server # Author : Leshami # Blog : http://blog.csdn.net/leshami # processname: nginx # pidfile: /var/run/nginx.pid # config: /etc/nginx/nginx.conf #path for nginx binary nginxd=/usr/sbin/nginx #path for nginx configuration nginx_config=/etc/nginx/nginx.conf #path for nginx pid nginx_pid=/var/run/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 # chmod u+x /etc/init.d/nginx # service nginx start Starting nginx: [ OK ] # ps -ef|grep nginx |grep -v grep root 33534 1 0 10:33 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 33535 33534 0 10:33 ? 00:00:00 nginx: worker process # service nginx stop Stopping nginx: [ OK ] # chkconfig --add nginx # chkconfig nginx on |
五、安装过程中的常见故障
| ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option. ./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option. ### 以上2个错误,请安装相应的依赖包,见本文第二部分:配置安装环境 # /usr/sbin/nginx nginx: [emerg] getpwnam("nginx") failed ### 需要创建nginx用户组及用户 # /usr/sbin/nginx nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (2: No such file or directory) ### 需要创建对应的目录 |








