首页 > 代码库 > CentOS安装Nginx
CentOS安装Nginx
1. 下载:http://nginx.org/en/download.html
2. 安装依赖:yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel
3. wget http://nginx.org/download/nginx-1.4.4.tar.gz
4. tar zxf nginx-1.4.4.tar.gz
5. cd nginx-1.4.4
6. ./configure
--prefix=<path> - Nginx安装路径。如果没有指定,默认为 /usr/local/nginx。
--sbin-path=<path> - Nginx可执行文件安装路径。只能安装时指定,如果没有指定,默认为<prefix>/sbin/nginx
--conf-path=<path> - 在没有给定-c选项下默认的nginx.conf的路径。如果没有指定,默认为<prefix>/conf/nginx.conf。
--pid-path=<path> - 在nginx.conf中没有指定pid指令的情况下,默认的nginx.pid的路径。如果没有指定,默认为 <prefix>/logs/nginx.pid。
--lock-path=<path> - nginx.lock文件的路径。
--error-log-path=<path> - 在nginx.conf中没有指定error_log指令的情况下,默认的错误日志的路径。如果没有指定,默认为 <prefix>/logs/error.log。
--http-log-path=<path> - 在nginx.conf中没有指定access_log指令的情况下,默认的访问日志的路径。如果没有指定,默认为 <prefix>/logs/access.log。
--user=<user> - 在nginx.conf中没有指定user指令的情况下,默认的nginx使用的用户。如果没有指定,默认为 nobody。
--group=<group> - 在nginx.conf中没有指定user指令的情况下,默认的nginx使用的组。如果没有指定,默认为 nobody。
--builddir=DIR - 指定编译的目录
--with-rtsig_module - 启用 rtsig 模块最后安装
7. make && make install
8. 设置成系统开机服务
在 /etc/init.d/ 目录下创建 nginx 文件 内容如下:
#!/bin/bash # nginx Startup script for the Nginx HTTP Server# this script create it by gcec at 2009.10.22.# it is v.0.0.1 version.# if you find any errors on this scripts,please contact gcec cyz.# and send mail to support at gcec dot cc.## 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/run/nginx.pid# config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0prog="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 1fi 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 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" instart) start ;;stop) stop ;;reload) reload ;;restart) stop start ;;status) status $prog RETVAL=$? ;;*) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1esacexit $RETVAL
9. 添加到服务:
chmod 0777 /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 345 nginx on
chkconfig --list nginx
启动
service nginx start
停止
service nginx stop
CentOS安装Nginx