近期因为项目原因须要使用nginx,所以看了一下。先从安装和配置開始。
(1) 安装依赖
依赖库直接使用yum安装a) 安装基本依赖工具
[[email protected] ~]# yum -y install gcc gcc-c++ automake autoconf libtool make
b) 安装prec
[[email protected] ~]# yum install pcre.x86_64 pcre-devel.x86_64
c) 安装zlib
[[email protected] ~]# yum install zlib.x86_64 zlib-devel.x86_64
d) 安装openssl
[[email protected] ~]# yum install openssl.x86_64 openssl-devel.x86_64
(2) 编译安装nginx
a) 下载安装包
[[email protected] ~]# wget http://nginx.org/download/nginx-1.4.7.tar.gz
b) 解压
[[email protected] ~]# tar -xvf nginx-1.4.7.tar.gz [[email protected] ~]# cd nginx-1.4.7
c) 安装i. 指定安装文件夹
[[email protected] ~]# ./configure --prefix=/usr/local/nginx/cache/
ii. make & make install
[[email protected] ~]# make [[email protected] ~]# make install
(3) 配置和启动
a) 配置文件使用默认的配置文件在安装文件夹下:conf/nginx.conf。默认使用80port。须要先使用netstat开一下80port是否已经被占用
[[email protected] ~]# netstat –nltp | grep 80
b) root启动nginx,
[[email protected] ~]# /usr/local/nginx/cache/sbin/nginx -c /usr/local/nginx/cache/conf/nginx.conf
(4) 改动防火墙规则
Centos的防火墙默认是打开的。须要加入对应的规则打开80port。a) 在另外一台机器上測试port,发现80port不通
[[email protected] ~]# telnet 10.237.92.30 80 Trying 10.237.92.30... telnet: Unable to connect to remote host: No route to host
b) Centos的防火墙默认是打开的,查看本机防火墙配置
[[email protected] ~]# service iptables status Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) num target prot opt source destination
c) 打开80port
[[email protected] ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
查看port会发现port通了
[email protected]:~$ telnet 10.237.92.30 80 Trying 10.237.92.30... Connected to 10.237.92.30. Escape character is ‘^]‘. ^]
d) 改动iptables配置文件使用iptables命令添加的规则在重新启动之后就失效了,要想规则在重新启动之后任然有效, 须要改动iptables配置文件/etc/sysconfig/iptables,添加以下的行。
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
时间: 2024-09-29 18:09:21