名称 | 角色 |
server ( RHEL5.5) | 服务器 |
1
、编译安装Nginx (1)安装依赖包pcre-devel、zlib-devel [root@localhost ~]# mount /dev/cdrom /media/ //挂载光盘 mount: block device /dev/sr0 is write-protected, mounting read-only [root@localhost ~]# vi /etc/yum.repos.d/rhel-source.repo
//编辑YUM文件 [rhel-source] name=Red Hat Enterprise Linux $releasever - $basearch - Source baseurl=file:///media/Server enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-RedHat-release [root@localhost ~]# yum -y install pcre-devel zlib-devel //YUM安装依赖包 (2)创建运行用户,组 [root@localhost ~]# useradd -M -u 27 -s /sbin/nologin nginx (3)编译安装Nginx [root@localhost ~]# tar zxf nginx-1.0.8.tar.gz [root@localhost ~]# cd nginx-1.0.8 [root@localhost nginx-1.0.8]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module ;make ;make install (4)创建软连接 [root@localhost nginx-1.0.8]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ [root@localhost nginx-1.0.8]# ll /usr/local/sbin/nginx lrwxrwxrwx 1 root root 27 4月 18 13:20 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx
2
、Nginx
的运行控制 (1)检查配置文件 [root@localhost ~]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful (2)启动Nginx [root@localhost ~]# nginx 查看运行状态 [root@localhost ~]# netstat -anpt |grep nginx tcp
0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9224/nginx: master 使用elink查看是否成功 [root@localhost ~]# elinks
http://localhost 重载、退出nginx [root@localhost ~]# kill -s HUP nginx [root@localhost ~]# kill -s QUIT nginx (3)编写Nginx服务脚本 [root@localhost ~]# vi /etc/init.d/nginx #!/bin/bash # chkconfig: - 99 20 # description: xxxxx PROG="/usr/local/nginx/sbin/nginx" PIDF="/usr/local/nginx/logs/nginx.pid" case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1 esac exit 0 [root@localhost ~]# chmod +x /etc/init.d/nginx //给予执行权限 [root@localhost ~]# chkconfig --add nginx //添加为系统服务 映射主机名 [root@localhost ~]# vi /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1
localhost.localdomain localhost ::1
localhost6.localdomain6 localhost6 192.168.1.1
www.benet.com www.accp.com
[root@localhost ~]# elinks
http://www.benet.com查看
//