菜鸟笔记
提升您的技术认知

服务器安装Nginx教程

1、安装所需依赖

yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

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

//进入/usr/local
cd /usr/local

//创建nginx目录
mkdir nginx

//进入nginx目录
cd nginx

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

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

3、安装Nginx

//进入nginx目录
cd /usr/local/nginx/nginx-1.20.1

//执行命令
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre --with-stream

//执行命令(如果不成功,检查yum安装的依赖是否成功)
make

//执行命令
make install

4、启动Nginx

//进入/usr/local/nginx/sbin目录,输入./nginx即可启动nginx
./nginx
 
//关闭nginx
./nginx -s quit  或者 ./nginx -s stop
 
//重启nginx
./nginx -s reload
 
//查看nginx进程
ps -ef|grep nginx

5、设置全局Nginx

//编辑/etc/profile
vim /etc/profile

//设置PATH
PATH=$PATH:/usr/local/nginx/sbin
export PATH

//执行命令
source /etc/profile