1、登录nginx官网 http://nginx.org/en/download.html 下载Stable version,如nginx-1.10.3
2、安装lrzsz工具 http://www.cnblogs.com/linuxchen/p/6600379.html
3、解压缩,安装 cd /usr/local/src/ tar -zxvf nginx-1.10.3.tar.gz cd nginx-1.10.3 ./configure 报错:./configure: error: C compiler cc is not found yum -y install gcc gcc-c++ autoconf automake -y自动选是,autoconf自动配置,automake自动编译 ./configure 报错:./configure: error: the HTTP rewrite module requires the PCRE library. yum -y install pcre pcre-devel ./configure 报错:./configure: error: the HTTP gzip module requires the zlib library. yum -y install zlib zlib-devel ./configure make make install
以上报错都是./congfigure时出现的,实际安装时可以省略除倒数第三个之外的./configure,gcc、pcre、zlib都是需要的库文件
4、cd /usr/local/nginx 下面有四个目录conf、html、logs、sbin四个目录 conf目录下是配置文件 html目录放置的是网页程序 logs目录下放置的日志 sbin目录下放置的启动的可执行文件
5、配置防火墙,开放80端口 停止firewall systemctl stop firewalld.service 禁止firewall开机启动 systemctl disable firewalld.service yum安装iptables防火墙 yum install iptables-services 编辑防火墙配置文件 vi /etc/sysconfig/iptables 配置文件增加80和3306新增红色两行 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACC EPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j A CCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT 重启防火墙使配置生效 systemctl restart iptables.service 设置防火墙开机启动 systemctl enable iptables.service
6、关闭SELINUX vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled #增加 :wq! #保存退出 setenforce 0 #使配置立即生效
7、输入IP地址,看到nginx的欢迎语表示安装成功 Welcome to nginx!(责任编辑:IT) |