Linux系统下nginx的安装
1.环境准备
1.1环境背景
1.2创建用户
- id mynginx || useradd -s /sbin/nologin mynginx
- 此用户用于启动nginx,若不存在此用户,将创建此用户,存在则不执行
1.3创建文件夹
- mkdir -p /nginx
- cd /nginx
2.下载压缩包
- curl -O http://nginx.org/download/nginx-1.21.4.tar.gz
3.解压
- tar xf nginx-1.21.4.tar.gz
- cd nginx-1.21.4
4.解决依赖关系
- yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make
5.生成编译前的配置工作,生成Makefile
- ./configure --user=mynginx --group=mynginx --prefix=/usr/local/mynginx --with-threads --with-http_ssl_module --with-http_realip_module --with-file-aio --with-http_stub_status_module --with-stream
6.编译安装
7.永久修改path变量
- echo “PATH=$PATH:/usr/local/mynginx/sbin” >>/root/.bashrc
- source /root/.bashrc
8.启动nginx
- /usr/local/mynginx/sbin/nginx
9.关闭防火墙
- service firewalld stop
- systemctl disable firewalld
- sed -i ‘/^SELINUX=/s/enforcing/disabled/’ /etc/sysconfig/selinux
10.一键安装脚本
#!/bin/bash
#创建用户 mynginx
id mynginx || useradd -s /sbin/nologin mynginx
#下载nginx
mkdir -p /nginx
cd /nginx
curl -O http://nginx.org/download/nginx-1.21.4.tar.gz
#解压
tar xf nginx-1.21.4.tar.gz
cd nginx-1.21.4
#解决依赖关系
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make
#生成编译前的配置工作,生成Makefile
./configure --user=mynginx --group=mynginx --prefix=/usr/local/mynginx --with-threads --with-http_ssl_module --with-http_realip_module --with-file-aio --with-http_stub_status_module --with-stream
#编译
make -j 2
#编译安装
make install
#修改path变量
echo "PATH=$PATH:/usr/local/mynginx/sbin" >>/root/.bashrc
#执行修改了环境变量的脚本
source /root/.bashrc
#启动nginx
/usr/local/mynginx/sbin/nginx
#关闭防火墙
service firewalld stop
systemctl disable firewalld
sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/sysconfig/selinux