安装 nginx 须要先将官网下载的源码进行编译,编译依赖 gcc 环境。linux
yum install gcc-c++
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,因此须要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx
yum install -y pcre pcre-devel
zlib 库提供了不少种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip 。c++
yum install -y zlib zlib-devel
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、经常使用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不只支持 http 协议,还支持 https(即在ssl协议上传输http)。正则表达式
yum install -y openssl openssl-devel
wget
命令下载安装wget -c https://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure
make
make install
whereis nginx
./nginx
./nginx -s stop #此方式至关于先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s quit #此方式中止步骤是待nginx进程处理任务完毕进行中止。
./nginx -s reload #当nginx的配置文件nginx.conf修改后,要想让配置生效须要重启nginx
./nginx -t #检测配置文件是否正常
pkill nginx #强制关闭
ps aux|grep nginx #查看nginx进程
#CentOS 7.0默认使用的是firewall做为防火墙
firewall-cmd --state #查看防火墙状态
systemctl stop firewalld.service #中止firewall
systemctl disable firewalld.service #禁止firewall开机启动
vim /etc/rc.local #新增一行/usr/local/nginx/sbin/nginx,设置执行权限chmod 755 rc.local,开机自动启动nginx