序言
NGINX是一个免费的,开源的,高性能的HTTP服务器和反向代理,以及IMAP / POP3代理服务器。NGINX以其高性能,稳定性,丰富的功能集,简单的配置和低资源消耗而闻名。
一、官网下载安装包
下载地址:http://nginx.org/download/ 里面包含 nginx 各个版本的安装包
wget -P /tmp/nginx/ http://nginx.org/download/nginx-1.14.0.tar.gz
wget命令 参数:
-P –directory-prefix=PREFIX 将文件保存到目录 PREFIX/… 目录不存在时会自己创建
-O –output-document=FILE 把文档写到FILE文件中 在指定路径的时候,目录要先自己创建
二、安装nginx依赖库
yum install gcc-c++ #gcc是用来编译下载下来的nginx源码
yum install pcre #是一个Perl库,包括 perl 兼容的正则表达式库
yum install pcre-devel #pcre-devel 是使用 pcre 开发的一个二次开发库
yum install zlib #zlib提供了很多压缩和解方式,nginx需要zlib对http进行gzip
yum install zlib-devel #zlib-devel 是使用 zlib开发的一个二次开发库
yum install openssl #openssl是一个安全套接字层密码库,nginx要支持https,需要使用openssl
yum install openssl-devel #openssl-devel 是使用 openssl开发的一个二次开发库
三、配置nginx用户和组
//添加nginx用户和组
groupadd nginx
useradd -s /sbin/nologin -M nginx -g nginx
四、安装nginx
- 解压nginx安装包
tar -zxvf nginx-1.14.0.tar.gz
- cd到文件路劲
- 编译
mkdir -p /var/tmp/nginx/client /var/tmp/nginx/proxy /var/tmp/nginx/fcgi ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_gzip_static_module \ --http-log-path=/var/log/nginx/access.log \ --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 \ --with-http_stub_status_module
- 安装
make && make install
- 防火墙配置
#centos7里面 使用的是firewall 要是用不习惯可以换iptables sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload #切换为iptables防火墙 service firewalld stop systemctl disable firewalld.service #禁止firewall开机启动 yum install iptables-services #安装 vim /etc/sysconfig/iptables #编辑防火墙配置文件 iptables -I INPUT -p tcp --dport 80 -j ACCEPT iptables -I INPUT -p tcp --dport 443-j ACCEPT
五、启动nginx
nginx -c /etc/nginx/nginx.conf #启动
nginx -s reload #配置文件修改重装载命令
nginx -s stop #快速停止或关闭Nginx
nginx -s quit #正常停止或关闭Nginx
六、验证
curl -i http://127.0.0.1