Nginx

Nginx

Nginx是一款轻量级的Web服务器 / 反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。

快速入门

第一步:官网下载Ngiax压缩包:Nginx

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210218184506839.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NhcmxlSA==,size_16,color_FFFFFF,t_70)

第二步:Nginx常用命令(cmd命令行输入)

  • 启动:nginx.exe / start nginx
  • 停止:nginx -s quit / nginx -s stop【stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息】
  • 重新载入Nginx:nginx -s reload【当配置信息修改,需要重新载入这些配置】
  • 重新打开日志文件:nginx -s reopen
  • 查看Nginx版本:nginx -v

第三步:浏览器测试请求路径 http://localhost/80(Nginx默认是80端口)

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210218185540457.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NhcmxlSA==,size_16,color_FFFFFF,t_70)

反向代理和负载均衡

步骤一:增加一个upstream,用来指向这两个tomcat,weight表示权重,值越大,被分配到的几率越大。

upstream tomcatTwoPort {
    server 127.0.0.1:8081 weight=1;
    server 127.0.0.1:8082 weight=3;
}

步骤二:然后修改location,反向代理到上述配置。

location / 表示处理所有请求

proxy_pass http://tomcatTwoPort; 表示把请求都交给http://tomcatTwoPort来处理

location / {
	proxy_pass   http://tomcatTwoPort;
}

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210219111439817.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NhcmxlSA==,size_16,color_FFFFFF,t_70)

步骤三:使用nginx -s reload重新加载配置。

参考资料

Nginx官方文档

How2j

posted @ 2021-02-19 11:46  你画我猜  阅读(201)  评论(0)    收藏  举报