一、安装准备
1.1 依赖安装
下载安装依赖
yum -y install wget gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre- devel
- gcc:gcc-c++编译环境
- gzip模块需要:zlib 库
- rewrite模块需要:pcre 库
- ssl功能需要:openssl库
1.2 nginx安装包下载
下载nginx安装包
wget http://nginx.org/download/nginx-1.14.2.tar.gz
1.3 创建用户与组
创建nginx组
groupadd nginx
# 创建一个不能登录属于nginx组的用户nginx
useradd nginx -g nginx -s /sbin/nologin -M
二、编译安装
解压
tar -zxvf nginx-1.14.2.tar.gz
切换目录
cd nginx-1.14.2
预编译
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module
#ngx-fancyindex-master模块请添加:
#--add-module=./ ngx-fancyindex-master
- –user=nginx(用户名)
- –group=nginx(组)
- –prefifix=/usr/local/nginx(程序安装路径)
- –with-http_stub_status_module (网页状态查看)
- –with-http_ssl_module (ssl模块)
- –with-http_realip_module (后台Nginx服务器记录原始客户端的IP地址 )
- –with-http_gzip_static_module (压缩模块)
查看预编译安装结果,显示最后命令的退出状态,0表示没有错误,其他表示有错误
echo $?
编译安装
make && make install
再次查看编译安装结果
echo $?
三、将nginx永久添加到系统变量
编辑系统变量文件
vim /etc/profile
将nginx变量添加到文件内后,wq保存
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
使配置文件生效
source /etc/profile
四、使用说明
对nginx进行启动|关闭|重载|重启|查看状态
systemctl start|stop|reload|restart|status nginx.service
开启|关闭nginx的开机自启动
systemctl enable|disable nginx