@TOC前言什么是nginx?Nginx是一个轻量级的网络服务器/反向代理服务器和电子邮件(IMAP/POP3)代理服务器。特点是占用内存少,并发能力特别强。nginx的作用?http代理,如:正向代理、反向代理。前者适合新手,后者适合老手(方便大家搜索,从而过滤掉某些步骤,节省时间成本),按需查看即可。详细版精简版精简版:包含所有步骤,以及命令的执行过程(适合新手)精简版:只包含命令(适合有一定熟练度的人)工作原理转发代理客户端--->代理服务器--->访问域名--->访问服务器客户端<---代理服务器<---访问域名<---访问服务器简单总结:正向代理是给客户端的举个栗子:我们打韩服的LOL有延迟,所以我们可以找一个代理(香港vpn),代理访问国外的服务器,然后返回给代理,最后返回给我们。可以理解为加速器。反向代理客户端--->访问的域名--->代理服务器--->访问的服务器客户端<---访问的域名<---代理服务器<---访问的服务器简述:反向代理是为了去服务器举个栗子:我们访问百度时,总是使用域名www.baidu.com。其实域名后面还有很多服务器(ip地址)。访问域名-->代理服务器后,我们会去百度服务器最后返回给我们html页面。环境准备系统VcpuMemory网卡类型centos724NAT模式没有hexo博客环境看这里:还能建博客吗?centos7系统部署hexo博客新手入门-进阶,看这篇文章就够了/etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-7.repo#下载epel源码,否则没有nginx包--2022-04-1821:54:35--http://mirrors.aliyun.com/repo/epel-7.repoResolvingmirrors.aliyun.com(mirrors.aliyun.com)...113.207.38.89,113.207.38.90,113.207.38.85,...正在连接到mirrors.aliyun.com(mirrors.aliyun.com)|113.207.38.89|:80...已连接.HTTP请求已发送,等待响应...200OKLength:664[application/octet-stream]保存到:'/etc/yum.repos.d/epel.repo'100%[============================================================================================>]664---.-K/sin0s2022-04-1821:54:36(131MB/s)-'/etc/yum.repos.d/epel.repo'saved[664/664]yumInstallnginx:[root@localhost~]#yuminstall-ynginx#yuminstallnginxsoftwareLoadedplugins:fastestmirrorLoadingmirrorspeedsfrom缓存主机le*base:mirrors.aliyun.com*extras:mirrors.aliyun.com*updates:mirrors.aliyun.comResolvingDependencies-->Runningtransactioncheck--->Packagenginx.x86_641:1.20.1-9.el7will被安装-->处理依赖:nginx-filesystem=1:1.20.1-9.el7forpackage:1:nginx-1.20.1-9.el7.x86_64-->处理依赖:libcrypto.so.1.1(OPENSSL_1_1_0)(64bit)forpackage:1:nginx-1.20.1-9.el7.x86_64-->ProcessingDependency:libssl.so.1.1(OPENSSL_1_1_0)(64bit)forpackage:1:nginx-1.20.1-9.el7.x86_64-->处理依赖:libssl.so.1.1(OPENSSL_1_1_1)(64bit)包:1:nginx-1.20.1-9.el7.x86_64-->处理依赖:nginx-filesystem包:1:nginx-1.20.1-9.el7.x86_64-->处理依赖:redhat-indexhtmlforpackage:1:nginx-1.20.1-9.el7.x86_64-->处理依赖:libcrypto.so.1.1()(64bit)forpackage:1:nginx-1.20.1-9.el7.x86_64-->ProcessingDependency:libprofiler.so.0()(64bit)forpackage:1:nginx-1.20.1-9.el7.x86_64-->ProcessingDependency:libssl.so.1.1()(64bit)forpackage:1:nginx-1.20.1-9.el7.x86_64启动nginx:[root@localhost~]#systemctlstopfirewalld&&systemctldisabelfirewalld#关闭防火墙,开机不启动防火墙[root@localhost~]#setenforce0#暂时关闭selinux[root@localhost~]#systemctlstartnginx#启动nginx[root@localhost~]#systemctlenablenginx#启动nginx浏览器验证是否可以访问nginx如图:配置default.conf文件实现反向代理:[root@localhost~]#cat/etc/nginx/conf.d/default.conf#如果没有conf.d目录需要创建,我们这里下载的nginx版本默认是没有default.conf的,直接创建即可server{listen80;服务器名称本地主机;#charsetkoi8-r;#access_log日志/host.access.logmain;位置/{#根html;#索引index.htmlindex.htm;proxy_passhttp://127.0.0.1:4000;#httproot/目录,代理到http://127.0.0.1:4000}}[root@localhost~]#systemctlrestartnginx最后验证一下,你会发现直接在浏览器输入ip,就可以访问了不进入4000端口就结束了,如下图:Uninstall[root@localhost~]#yumremove-ynginx#yum载nginxLoadedplugins:fastestmirrorResolvingDependencies-->Runningtransactioncheck--->Packagenginx.x86_641:1.20.1-9.el7willbeerased-->FinishedDependencyResolutionDependenciesResolved============================================================================================================================包Arch版本存储库大小============================================================================================================================删除:nginxx86_641:1.20.1-9.el7@epel1.7MTransaction摘要============================================================================================================================删除1PackageInstalledsize:1.7MDownloadingpackages:RunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionErasing:1:nginx-1.20.1-9.el7.x86_641/1warning:/etc/nginx/nginx.confsavedas/etc/nginx/nginx.conf.rpmsave验证:1:nginx-1.20.1-9.el7.x86_641/1Removed:nginx.x86_641:1.20.1-9.el7Complete![root@localhost~]#rm-rf/etc/nginx*#删除相关配置文件目录简洁版本搭建步骤wget-O/etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-7.repoyuminstall-ynginx[root@localhost~]#systemctlstopfirewalld&&systemctldisabelfirewalld浏览器认证[root@localhost~]#setenforce0[root@localhost~]#systemctlstartnginx[root@localhost~]#systemctlenablenginx[root@localhost~]#cat/etc/nginx/conf.d/default.confserver{听80;服务器名称本地主机;#charsetkoi8-r;#access_log日志/host.access.logmain;位置/{#根html;#索引index.htmlindex.htm;proxy_passhttp://127.0.0.1:4000;}}[root@localhost~]#systemctlrestartnginx浏览器验证卸载[root@localhost~]*#yumremove-ynginx*[root@localhost~]*#rm-rf/etc/nginx**
