• Nginx+Tomcat负载均衡、动静分离


    七层反向代理+动静分离

    1. 实验配置:
    2. nginx:20.0.0.61 代理又是静态
    3. tomcat1:20.0.0.71
    4. tomcat2:20.0.0.72
    1. [root@nginx1 conf]# vim nginx.conf
    2. http {
    3. ...
    4. upstream tomcat {
    5. server 20.0.0.71:8080 weight=1;
    6. server 20.0.0.72:8080 weight=1;
    7. }
    8. server {
    9. ...
    10. location / {
    11. root html;
    12. index index.html index.htm;
    13. }
    14. location ~* \.jsp$ {
    15. proxy_pass http://tomcat;
    16. proxy_set_header HOST $host;
    17. proxy_set_header X-Real-IP $remote_addr;
    18. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    19. }
    20. [root@nginx1 conf]# nginx -t
    21. [root@nginx1 conf]# systemctl restart nginx

    1. [root@nginx1 conf]# cd ..
    2. [root@nginx1 nginx]# cd html/
    3. [root@nginx1 html]# vim index.html
    4. <html>
    5. <body>
    6. <h1> this is Nginx static test1 !</h2>
    7. <img src="naruto.PNG"/>
    8. </body>
    9. </html>
    10. --传入naruto.PNG--

    浏览器访问20.0.0.61

    1. [root@tomcat1 ~]# cd /usr/local/tomcat/
    2. [root@tomcat1 tomcat]# cd webapps/
    3. [root@tomcat1 webapps]# mkdir test
    4. [root@tomcat1 webapps]# cd test/
    5. [root@tomcat1 test]# vim index.jsp
    6. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    7. JSP test1 page
    8. <% out.println("动态页面 1,http://www.test1.com");%>
    9. [root@tomcat2 ~]# cd /usr/local/tomcat/
    10. [root@tomcat2 tomcat]# cd webapps/
    11. [root@tomcat2 webapps]# mkdir test
    12. [root@tomcat2 webapps]# cd test/
    13. [root@tomcat2 test]# vim index.jsp
    14. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    15. JSP test2 page
    16. <% out.println("动态页面 2,http://www.test2.com");%>
    1. 7172相同操作:
    2. [root@tomcat1 conf]# vim server.xml
    3. --删除--
    4. "localhost" appBase="webapps"
    5. unpackWARs="true" autoDeploy="true">
    6. --插入--
    7. "localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> "/usr/local/tomcat/webapps/test" path="" reloadable="true" />

    1. 7172相同操作:
    2. [root@tomcat1 conf]# cd ..
    3. [root@tomcat1 tomcat]# cd bin/
    4. [root@tomcat1 bin]# ./startup.sh

    浏览器直接访问71、72动态页面

    浏览器访问代理服务器跳转至动态页面

    四层+七层+动静分离

    1. 实验配置:
    2. nginx代理:20.0.0.61
    3. 静态页面和动态请求转发服务器:
    4. nginx2:20.0.0.62
    5. nginx3:20.0.0.63
    6. tomcat1:20.0.0.71
    7. tomcat2:20.0.0.72
    1. [root@nginx1 conf]# vim nginx.conf
    2. stream {
    3. upstream static {
    4. server 20.0.0.62:80 weight=1;
    5. server 20.0.0.63:80 weight=1;
    6. }
    7. server {
    8. listen 80;
    9. proxy_pass static;
    10. }
    11. }
    12. [root@nginx1 conf]# nginx -t
    13. [root@nginx1 conf]# systemctl restart nginx

    1. 6263相同操作:
    2. [root@nginx2 conf]# vim nginx.conf
    3. upstream tomcat {
    4. server 20.0.0.71:8080 weight=1;
    5. server 20.0.0.72:8080 weight=1;
    6. }
    7. server {
    8. listen 80;
    9. server_name localhost;
    10. location / {
    11. root html;
    12. index index.html index.htm;
    13. }
    14. location ~* \.jsp$ {
    15. proxy_pass http://tomcat;
    16. proxy_set_header HOST $host;
    17. proxy_set_header X-Real-IP $remote_addr;
    18. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    19. }

    1. [root@nginx2 html]# vim index.html
    2. this is Nginx static test1 !

    3. "naruto.PNG"/>
    4. --传入naruto.PNG--
    5. [root@nginx3 html]# vim index.html
    6. this is Nginx static test2 !

    7. "sasuke.PNG"/>
    8. --传入sasuke.PNG--

    浏览器访问20.0.0.61请求静态页面

    浏览器访问20.0.0.61动态页面跳转

  • 相关阅读:
    flex布局(弹性盒子三)
    vue2中使用ueditor百度富文本,并支持插入公式
    AES高级加密协议的动机阐述
    数据结构-例题实训作业-二叉树相关
    (5)多机器人集群编队策略
    Netty深入浅出Java网络编程学习笔记(三) 优化篇
    k8s安装使用教程 ingress
    选择图像区域矩形框控件【原创】
    springboot基于Android的洗衣店预约APP毕业设计源码260839
    FFmpeg之转码
  • 原文地址:https://blog.csdn.net/pupcarrot/article/details/133899955