nginx编译安装并启动
本次安装基于CentOS Linux release 7.7.1908 (Core)
1.依赖包安装
yum install pcre pcre-devel openssl openssl-devel -y (其中openssl相关包,https服务需要)
2.检查依赖包安装结果
rpm -qa pcre pcre-devel openssl openssl-devel
3.创建包存放路径
mkdir -p /home/heng/tools
cd /home/heng/tools
4.下载nginx软件包
wget http://nginx.org/download/nginx-1.18.0.tar.gz
5.创建nginx用户
useradd nginx -s /sbin/nologin -M
6.解压nginx软件包
tar xf nginx-1.18.0.tar.gz
7.进入目录,开始配置
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module
--prefix 设置安装路径
--user 进程用户权限
--group 进程用户组权限
8.编译安装
make && make install
9.创建软连接
ln -s /application/nginx-1.18.0/ /application/nginx
10.启动前检查配置文件语法
/application/nginx/sbin/nginx -t
11.启动nginx
/application/nginx/sbin/nginx
12.查看nginx是否启动成功
netstat -lntup | grep 80
nginx一键安装shell脚本,亲测可用
#!/bin/bash #Program: # install nginx #History: #2021/05/25 heng First relase PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk/bin:/usr/local/python3.8/bin:/root/bin" export PATH downloadPath="/home/heng/tools" # nginx包下载路径 # 1.nginx安装依赖环境准备 yum install pcre pcre-devel openssl openssl-devel -y if [ $? != 0 ]; then echo "依赖环境安装失败!" exit 1 fi # 2.创建包存放路径 if [ ! -d ${downloadPath} ]; then echo "下载目录不存在,创建目录.." mkdir -p ${downloadPath} && cd ${downloadPath} else cd ${downloadPath} fi # 3.下载nginx包 which wget if [ $? != 0 ]; then # 判断wget是否存在,不存在就先安装wget命令 echo "wget does not exist! install..." yum install wget -y fi wget -q http://nginx.org/download/nginx-1.18.0.tar.gz # 4.创建nginx用户 useradd nginx -s /sbin/nologin -M # 5.解压软件包 tar xf nginx-1.18.0.tar.gz && cd nginx-1.18.0 # 6.配置编译安装 ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.18.0/ --with-http_stub_status_module --with-http_ssl_module && make && make install if [ $? != 0 ]; then echo "make failed!" exit 1 fi # 7.建立软连接 ln -s /application/nginx-1.18.0/ /application/nginx exit 0