巨详细Linux安装Nginx教程
1、检查是否残留数据
#检查残留数据(为空就是没有残留数据)
rpm -qa | grep nginx
2、上传压缩包至服务器
2.1压缩包获取
Nginx各版本下载地址:http://nginx.org/en/download.html
2.2创建相关目录
如果你使用过我的巨详细系列其他文档,这一波可以跳过
#创建压缩包存放目录
mkdir -p /data/install
#创建安装目录
mkdir -p /data/local
之后将下载好的压缩包上传至/data/install/目录下,过程略。
3、安装Nginx
3.1解压Nginx压缩包
#创建nginx目录
mkdir -p /data/local/nginx
#进入nginx
cd /data/local/nginx
#解压压缩包到当前目录
tar zxvf /data/install/nginx-1.24.0.tar.gz -C ./
3.2下载所需依赖
#进入nginx-1.24.0
cd nginx-1.24.0/
#下载所需依赖
yum -y install pcre-devel
yum -y install openssl openssl-devel
等待下载完毕
3.3安装Nginx本体
#编译生成二进制文件
./configure --prefix=/data/local/nginx --with-http_ssl_module
#配置参数(这是一整条命令)
./configure --prefix=/data/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_stub_status_module --with-stream --with-stream_ssl_module
#编译安装
make && make install
编译生成二进制文件
配置参数
编译安装
4、配置Nginx
4.1把nginx进程交给systemctl管理
#创建配置文件并新增内容
vi /etc/systemd/system/nginx.service
添加如下内容后保存(如果路径和版本号不一样,悉数更改)
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/local/nginx/sbin/nginx -c /data/local/nginx/conf/nginx.conf
ExecReload=/data/local/nginx/sbin/nginx -s reload
ExecStop=/data/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
4.2设置nginx开机自启动
先普通方式启停nginx测试整体功能
#进入/data/local/nginx/sbin目录下
cd /data/local/nginx/sbin/
#启动 nginx
./nginx
#查看nginx运行状态
ps -ef | grep nginx
#停止 nginx
./nginx -s stop
启动停止正常
配置nginx开机自启动
#重新加载systemd的主配置文件
systemctl daemon-reload
#启动nginx
systemctl start nginx
#开机启动nginx
systemctl enable nginx
#查看nginx运行状态
systemctl status nginx
这样就可以了