CentOS编译安装Nginx
简介
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。其特点是占有内存少,并发能力强,Nginx采用C进行编写,一般情况下用Nginx来处理静态文件。
编译安装Nginx
在Centos下,yum源不提供nginx的安装,可以通过切换yum源的方法获取安装。也可以通过直接下载安装包的方法,下面主要讲通过安装包方式编译安装,注:以下命令需要以root权限执行:
1.安装gcc gcc-c++(如果已安装请跳过)
yum -y install gcc gcc-c++
2.官网下载安装包
1.15.2版本下载地址
http://nginx.org/download/nginx-1.15.2.tar.gz
查看所有版本下载地址:
http://nginx.org/en/download.html
3.解压下载的文件包
tar -xzvf nginx-1.15.2.tar.gz
4.编译安装nginx
cd nginx-1.15.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make
make install
如果报错提示:
./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel与openssl-devel解决问题,不报错不需要执行以下语句
yum -y install pcre-devel openssl openssl-devel
Nginx相关操作
启动Nginx
/usr/local/nginx/sbin/nginx
重启:
/usr/local/nginx/sbin/nginx -s reload
停止:
/usr/local/nginx/sbin/nginx -s stop
测试配置文件是否正常:
/usr/local/nginx/sbin/nginx -t -c 配置文件路劲
强制关闭:
pkill nginx
热加载配置文件
nginx -s reload
启动Nginx后用,用浏览器输如ip出现Nginx的欢迎页面就表示安装好了
如果不能访问有可能是防火墙没有放行80端口,关闭防火墙就行了
查看防火墙运行状态
systemctl status firewalld.service
停止防火墙
systemctl stop firewalld.service
关闭开机启动防火墙
systemctl disable firewalld.service
开机启动防火墙
systemctl enable firewalld.service
如果是CentOS6使用的是iptables做防火墙
查看防火墙运行状态
/etc/init.d/iptables status
关闭防火墙
/etc/init.d/iptables stop
永久关闭防火墙
chkconfig –level 35 iptables off
上一篇 : Linux基本目录简单介绍
下一篇 : CentOS常用网络配置命令