栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java学习 --- nginx配置动静分离

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java学习 --- nginx配置动静分离

一、将项目部署到linux下的tomcat上

 二、使用反向代理
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    

    sendfile        on;
    keepalive_timeout  65;
  #配置多台服务器
   upstream yaya{
  server 192.168.200.131:80 weight=7;
  server 192.168.200.132:80 weight=2;
  server 192.168.200.133:80 weight=1;
}

    server {
        listen       80;
        server_name  localhost;

        location / {
            #代理到服务器133服务器
            proxy_pass http://192.168.200.133:8080;
           # root   html;
            #index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

测试访问;

 三、普通的配置动静分离
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    

    sendfile        on;
    keepalive_timeout  65;
  #配置多台服务器
   upstream yaya{
  server 192.168.200.131:80 weight=7;
  server 192.168.200.132:80 weight=2;
  server 192.168.200.133:80 weight=1;
}

    server {
        listen       80;
        server_name  localhost;

        location / {
            #代理到服务器
            proxy_pass http://192.168.200.133:8080;
        }
      #配置静态文件
       location /images {
            root html;
            index index.html index.htm;
        }
      location /js {
            root html;
            index index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 四、使用正则表达式配置
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    

    sendfile        on;
    keepalive_timeout  65;
  #配置多台服务器
   upstream yaya{
  server 192.168.200.131:80 weight=7;
  server 192.168.200.132:80 weight=2;
  server 192.168.200.133:80 weight=1;
}

    server {
        listen       80;
        server_name  localhost;

        location / {
            #代理到服务器
            proxy_pass http://192.168.200.133:8080;
        }
      #使用正则表达式
       location ~*/(images|js) {
            root html;
            index index.html index.htm;
        }
      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/874105.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号