1、 下载nginx
官网地址:http://nginx.org/en/download.html
2、安装支持库
yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
3、解压编译安装
tar -zxvf nginx-1.7.12.tar.gz cd nginx-1.7.12 ./configure --prefix=/usr/local/nginx make && make install
4、添加自启动
自启动脚本如下,注意修改DAEMON和SCRIPTNAME:
vi /etc/init.d/nginx
#!/bin/sh # chkconfig: 2345 85 15 # Startup script for the nginx Web Server # description: nginx is a World Wide Web server. # It is used to serve HTML files and CGI. # processname: nginx # pidfile: /usr/local/nginx/logs/nginx.pid # config: /usr/local/nginx/conf/nginx.conf PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="nginx deamon" NAME=nginx DAEMON=/usr/local/nginx/sbin/$NAME SCRIPTNAME=/etc/init.d/$NAME test -x $DAEMON || exit 0 d_start(){ $DAEMON || echo -n "already running" } d_stop(){ $DAEMON -s quit || echo -n "not running" } d_reload(){ $DAEMON -s reload || echo -n "can not reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" d_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" d_stop echo "." ;; reload) echo -n "Reloading $DESC conf..." d_reload echo "reload ." ;; restart) echo -n "Restarting $DESC: $NAME" d_stop sleep 2 d_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 server nginx start
netstat -nltp;
可以看到nginx已经启动成功。
5、修改防火墙规则
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
service iptables restart
6、验证
浏览器输入:http://ip,可以看到:
浙公网安备 33010602011771号