nginx基础:
1,nginx是什么?
Nginx是一种http和反向代理服务器。一般我们用它将服务端上的网页或程序以一个地址或者域名的方式共享在网络上,客户机可通过此地址与域名进行访问。
2,nginx的优点:
开源,高并发,跨平台,稳定,负载均衡。
3,nginx的安装
1)yum安装:
官网链接:http://nginx.org/en/linux_packages.html#RHEL-CentOS,可根据网页直接配置。
1,安装nginx所需要的环境
yum -y install yum-utils,
2,创建nginx源(待会我们要安装主线版,就将mainline的enable设为1,stable的设为0)
vi /etc/yum.repos.d/nginx.repo
输入:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
3,安装nginx
yum -y install nginx
4,启动nginx
systemctl restart nginx
systemctl enable nginx 开机自启
5,关闭
systemctl stop nginx
systemctl disable nginx 永久关闭
2)源码安装
1,下载源码包,按需求下载。
http://nginx.org/en/download.html
2,安装nginx所需环境
yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel
3,将源码包上传至Linux系统中,使用rz上传,安装rz:
yum -y install lrzsz-0.12.20-36.el7.x86_64
在命令行输入rz,选择下载的nginx包。
4,解压 tar -xf nginx-1.19.10.tar
5,进入加压后的nginx文件
cd nginx
6,指定安装路径,进入文件后输入:
./configure --prefix=/usr/local/nginx
7,编译,安装
make && make install
8,安装完成,启动
/user/local/nginx/sbin/nginx
9,关闭:
usr/local/httpd/sbin/nginx -s stop