安装Tengine nginx 之后不能访问,配置防火墙

安装 tengine

1、依赖 gcc openssl-devel pcre-devel zlib-devel

• 安装:yum install gcc openssl-devel pcre-devel zlib-devel

2、上传tengine-2.1.0.tar.gz到linux中
3、tar -zxvf tengine-2.1.0.tar.gz
4、预编译:

./configure \
 --prefix=/opt/soft/tengine-2.1.0/ \
 --error-log-path=/var/log/nginx/error.log \
 --http-log-path=/var/log/nginx/access.log \
 --pid-path=/var/run/nginx/nginx.pid \
 --lock-path=/var/lock/nginx.lock \
 --with-http_ssl_module \
 --with-http_flv_module \
 --with-http_stub_status_module \
 --with-http_gzip_static_module \
 --http-client-body-temp-path=/var/tmp/nginx/client/ \
 --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
 --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
 --http-scgi-temp-path=/var/tmp/nginx/scgi \
 --with-pcre

5、编译安装:

make && make install

6、添加配置文件:

·创建目录

mkdir -p /var/tmp/nginx/client/
vim /etc/init.d/nginx

·添加配置

#!/bin/bash
#
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/opt/soft/tengine-2.1.0/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/opt/soft/tengine-2.1.0/conf/nginx.conf"

#[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

#make_dirs() {
#   # make required directories
#   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
#   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
#   for opt in $options; do
#       if [ `echo $opt | grep '.*-temp-path'` ]; then
#           value=`echo $opt | cut -d "=" -f 2`
#           if [ ! -d "$value" ]; then
#               # echo "creating" $value
#               mkdir -p $value && chown -R $user $value
#           fi
#       fi
#   done
#}

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    #    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    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() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
#  -HUP是nginx平滑重启参数  
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

·添加开机启动

1)、chkconfig –add nginx 出现以下出错表示
[root@node2 init.d]# chkconfig –add nginx
service nginx does not support chkconfig
2)、chkconfig nginx on
3)、chkconfig –list nginx
解决:
发现如果想添加脚本用service启动,必须要脚本里面包含这2行:

# chkconfig: - 85 15
# description: nginx ischkconfig  nginx on a World Wide Web server. It is used to serve

4)、修改权限 chmod 777 /etc/init.d/nginx
5)、启动服务 /etc/init.d/nginx start


辛辛苦苦编译安装完Ngnix,后发现不能访问,后来发现是防火墙把80端口给禁用了。开启之:(以下参考自:http://llhdf.javaeye.com/blog/526176

1.添加配置

vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

2.查看是否已经有了:

[root@vcentos ~]# /etc/init.d/iptables status 
Table: filter 
Chain INPUT (policy ACCEPT) 
num  target     prot opt source               destination         
1    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:80 
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80 
3    RH-Firewall-1-INPUT  all  --  0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT) 
num  target     prot opt source               destination         
1    RH-Firewall-1-INPUT  all  --  0.0.0.0/0            0.0.0.0/0

3.重启防火墙

/etc/init.d/iptables restart

4.启动Nginx服务

cd /etc/init.d/ && service nginx stop

5.添加开机启动

执行 chkconfig –add nginx时出现下面情况

[root@node1 ~]# chkconfig --add nginx
service nginx does not support chkconfig

解决:将下面的代码复制到赏面的nginx文件中
#!/bin/bash
# Startup script for the nginx Web Server
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve

再次执行

**[root@node1 init.d]# chkconfig –add nginx
[root@node1 init.d]# chkconfig –list nginx
nginx 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@node1 init.d]# chkconfig nginx on
[root@node1 init.d]# chkconfig –list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off**

添加开机启动成功


防火墙常用命令

1.这里应该也可以不重启计算机:

/etc/init.d/iptables restart

防火墙的关闭,关闭其服务即可:

2.查看防火墙信息:

/etc/init.d/iptables status

3.关闭防火墙服务:

/etc/init.d/iptables stop

4.永久关闭防火墙

我们也可以永久的关闭防火墙,但是我不建议大家这样做.永久关闭防火墙可以这样:

chkconfig iptables off                  

也可以直接修改,开放某个端口

/etc/sysconfig/iptables

添加一条

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值