0%

Linux安装Nginx

1、安装所需环境

1
2
3
4
5
6
7
8
9
10
11
//安装gcc
yum install gcc-c++

//安装PCRE pcre-devel
yum install -y pcre pcre-devel

//安装zlib
yum install -y zlib zlib-devel

//安装Open SSL
yum install -y openssl openssl-devel

2、创建nginx目录并下载安装包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//进入usr/local目录
cd /usr/local

//创建nginx目录
mkdir nginx

//进入nginx目录
cd nginx

//下载tar包
wget http://nginx.org/download/nginx-1.22.1.tar.gz

//解压tar
tar -xvf nginx-1.22.1.tar.gz

3、安装nginx

1
2
3
4
5
6
7
8
9
10
11
//进入nginx目录
cd /usr/local/nginx/nginx-1.22.1

//执行命令
./configure

//执行make命令(要是执行不成功请检查最开始安装的四个有没有安装成功)
make

//执行make install命令
make install

4、启动nginx

1
2
3
4
5
6
7
8
9
10
11
//进入/usr/local/nginx/sbin目录,输入./nginx即可启动nginx
./nginx

//关闭nginx
./nginx -s quit 或者 ./nginx -s stop

//重启nginx
./nginx -s reload

//查看nginx进程
ps -ef|grep nginx

5、设置开启自启动

1
2
3
4
5
//编辑
vim /etc/rc.local

//最底部增加这一行
/usr/local/nginx/sbin/nginx

6、日志路径

1
/var/log/nginx