美文网首页
Nginx反向代理-负载均衡配置

Nginx反向代理-负载均衡配置

作者: AC编程 | 来源:发表于2020-04-10 08:59 被阅读0次

    一、IP地址反向代理-负载均衡配置

    upstream supermarket_api {
       server 47.105.*.74:8002 weight=1;
       server 39.108.*.186:8800 weight=4;
       server 127.0.0.1:8002 weight=5;
    }
        
    
    server {  
        listen 8880;
        server_name 47.115.*.11;
             
        location /app{
          proxy_pass http://supermarket_api;
          proxy_set_header Host $host;
        } 
    }
    

    注:为了安全性,部分IP用*号做了代替

    二、域名反向代理-负载均衡配置

    
    upstream supermarket_server{
       # AC-ECS
       server 47.105.146.*:8002 weight=1;
       # ECS-test
       server 39.108.*.186:8800 weight=5;
       # ECS-backup-prod
       server 47.115.*.11:8002 weight=5;
    }
    
    server{
      listen 80;
      server_name test.com  www.test.com;
      location /{
         proxy_set_header   Host             $host;
         proxy_set_header   X-Real-IP        $remote_addr;
         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
         proxy_pass http://127.0.0.1:6002;
      }
      
      # 访问服务器文件(图片)
      location /files{
        proxy_pass http://47.115.*.11:8002;
        proxy_set_header Host $host;
      }
    
      # 将文件(图片)上传到指定一台服务器
      location /app/files/upload{
         proxy_pass http://47.115.*.11:8002;
         proxy_set_header Host $host;
      }
      
      location /manage/files/upload{
        proxy_pass http://47.115.*.11:8002;
        proxy_set_header Host $host;
      }  
    
      location /login{
        proxy_pass http://supermarket_server;
        proxy_set_header Host $host;
      }
      
      location /manage{
        proxy_pass http://supermarket_server;
        proxy_set_header Host $host;
      }
    
      location /app{
        proxy_pass http://supermarket_server;
        proxy_set_header Host $host;
      }
    
    }
    
    server{
      listen 6002;
      server_name 127.0.0.1;
      root /data/pc/supermarket/dist;
      location /{
        root /data/pc/supermarket/dist;
        index index.html;
        try_files $uri $uri/ /index.html;
      }
    
      location /home{
        rewrite .* /index.html break;
        root /data/pc/supermarket/dist;
      }
    }
    

    最后给大家送波福利

    阿里云折扣快速入口

    相关文章

      网友评论

          本文标题:Nginx反向代理-负载均衡配置

          本文链接:https://www.haomeiwen.com/subject/arrlmhtx.html