【代理是什么(】nginx快速入门+反向代理hexo个人博客)
@TOC
前言
- 什么是nginx?
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。特点是占有内存少,并发能力特别强。 - nginx作用?
http代理,如:正向代理、反向代理
本文说明请大家务必查看
前者适合新手,后者适合老手(方便大家查找,从而过滤掉某些步骤,节约时间成本) 所以大家按需查看哟。
详细版 | 简洁版 |
---|
简洁版:只包含命令(适合有一定熟练度的人)
工作原理 正向代理
- 客户端--->代理服务器--->访问的域名--->访问的服务器
- 客户端<---代理服务器<---访问的域名<---访问的服务器
简单总结:正向代理是到客户端
LOL
有延迟,我们就可以找一个代理(香港的
),代理访问国外的服务器,然后返回给代理,最后返回给我们。可以理解成加速器。文章图片
反向代理
- 客户端--->访问的域名--->代理服务器--->访问的服务器
- 客户端<---访问的域名<---代理服务器<---访问的服务器
简单总结:反向代理是到服务端
www.baidu.com
这个域名,其实域名后面有很多服务器(ip地址),访问域名-->代理服务器后到百度的服务器,最后返回给我们html页面。文章图片
环境准备
系统 | Vcpu | Memory | 网卡类型 |
---|---|---|---|
centos7 | 2 | 4 | NAT模式 |
详细版
入门:搭建步骤
配置阿里云epel源:
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo#下载epel源,否则没有nginx包
--2022-04-18 21:54:35--http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 113.207.38.89, 113.207.38.90, 113.207.38.85, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|113.207.38.89|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’100%[======================================================================================>] 664--.-K/sin 0s2022-04-18 21:54:36 (131 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]
yum安装nginx:
[root@localhost ~]# yum install -y nginx#yum安装nginx软件
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.20.1-9.el7 will be installed
--> Processing Dependency: nginx-filesystem = 1:1.20.1-9.el7 for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: redhat-indexhtml for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
--> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
启动nginx:
[root@localhost ~]# systemctl stop firewalld && systemctl disabel firewalld#关闭防火墙、开机不自启防火墙
[root@localhost ~]# setenforce 0#临时关闭selinux
[root@localhost ~]# systemctl start nginx #启动nginx
[root@localhost ~]# systemctl enable nginx #开机自启nginx
【【代理是什么(】nginx快速入门+反向代理hexo个人博客)】浏览器验证访问nginx如图所示:
文章图片
配置default.conf文件 实现反向代理:
[root@localhost ~]# cat /etc/nginx/conf.d/default.conf# 如果没有conf.d目录需要创建,默认我们这里下载的nginx版本没有default.conf,创建即可server {
listen80;
server_namelocalhost;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
# roothtml;
# indexindex.html index.htm;
proxy_pass http://127.0.0.1:4000;
#http根/目录,代理到http://127.0.0.1:4000
}
}[root@localhost ~]# systemctl restart nginx
最后验证
你会发现直接浏览器输入
ip
,不输入4000
端口也实现了访问over
如下图所示:文章图片
文章图片
卸载
[root@localhost ~]# yum remove -y nginx#yum卸载nginx
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.20.1-9.el7 will be erased
--> Finished Dependency ResolutionDependencies Resolved================================================================================================================================
PackageArchVersionRepositorySize
================================================================================================================================
Removing:
nginxx86_641:1.20.1-9.el7@epel1.7 MTransaction Summary
================================================================================================================================
Remove1 PackageInstalled size: 1.7 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing: 1:nginx-1.20.1-9.el7.x86_641/1
warning: /etc/nginx/nginx.conf saved as /etc/nginx/nginx.conf.rpmsave
Verifying: 1:nginx-1.20.1-9.el7.x86_641/1Removed:
nginx.x86_64 1:1.20.1-9.el7Complete![root@localhost ~]# rm -rf /etc/nginx*#删除相关配置文件目录
简洁版 搭建步骤
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y nginx
[root@localhost ~]# systemctl stop firewalld && systemctl disabel firewalld
浏览器 验证[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
[root@localhost ~]# cat /etc/nginx/conf.d/default.confserver {
listen80;
server_namelocalhost;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
# roothtml;
# indexindex.html index.htm;
proxy_pass http://127.0.0.1:4000;
}
}
[root@localhost ~]# systemctl restart nginx
浏览器 验证
卸载
[root@localhost ~]*# yum remove -y nginx*
[root@localhost ~]*# rm -rf /etc/nginx**
推荐阅读
- 2022年4月19日,第12天
- ps默认前背景色工具快捷键是什么
- PS添加锚点工具是什么
- 手机怎么打开Excel表格
- 安卓手机excel下载方法
- Mybatis中Mapper代理形式开发与spring整合
- win xp系统如何修正图片中歪掉的水平线【图文详细教程】
- win xp系统下word文档如何添加大括号【图文详细教程】
- 【教资】高中教师笔试-信息技术速通备考笔记
- 手机word打开异常