docker-compose 线上部署问题

Blade 未结 1 722

一、该问题的重现步骤是什么?

1. 不了解部署两个nginx,blade-nginx 和 web-nginx 的区别

2. 我现在部署的方式是全部开放端口,感觉没有使用到gateway

3.


二、你期待的结果是什么?实际看到的又是什么?


        所有请求由gateway 分发,实际看到的是请求由nginx 分发,希望修改部署配置


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

开源版 3.0.1 linux 


四、请提供详细的错误堆栈信息,这很重要。


docker-compose 配置

version: '3'
services:
  
  web-nginx:
    image: nginx:latest
    container_name: nginx
    volumes:
      - ./dist:/home/bluebook/dist
      - /home/bluebook/nginx/html:/home/bluebook/nginx/html
      - /home/bluebook/nginx/sslkey:/home/bluebook/nginx/sslkey
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - 80:80
      - 443:443
    networks:
      - bluebook
      
  blade-gateway:
    image: anapsix/alpine-java:8_server-jre_unlimited
    container_name: blade-gateway
    working_dir: /home/blade/gateway
    expose:
      - "80"
    volumes:
      - ./blade-gateway:/home/blade/gateway
    entrypoint: java -jar -Djava.security.egd=file:/dev/./urandom -server  -Xms256M -Xmx1g blade-gateway.jar --spring.profiles.active=prod
    networks:
      - bluebook
      
  blade-shop:
    image: anapsix/alpine-java:8_server-jre_unlimited
    container_name: blade-shop
    working_dir: /home/blade/shop
    ports:
      - "8107:8107"
    volumes:
      - ./blade-shop:/home/blade/shop
    entrypoint: java -jar -Djava.security.egd=file:/dev/./urandom -server  -Xms256M -Xmx1g  blade-shop.jar --spring.profiles.active=prod
    networks:
      - bluebook
      

  blade-usercenter:
    image: anapsix/alpine-java:8_server-jre_unlimited
    container_name: blade-usercenter
    working_dir: /home/blade/usercenter
    ports:
      - "8705:8705"
    volumes:
      - ./blade-usercenter:/home/blade/usercenter
    entrypoint: java -jar -Djava.security.egd=file:/dev/./urandom -server -Xms256M -Xmx1g  blade-usercenter.jar --spring.profiles.active=prod
    networks:
      - bluebook


      
  blade-discount:
    image: anapsix/alpine-java:8_server-jre_unlimited
    container_name: blade-discount
    working_dir: /home/blade/discount
    ports:
      - "8109:8109"
    volumes:
      - ./blade-discount:/home/blade/discount
    entrypoint: java -jar -Djava.security.egd=file:/dev/./urandom -server  -Xms1g -Xmx1g blade-discount.jar --spring.profiles.active=prod
    networks:
      - bluebook  

  blade-product:
    image: anapsix/alpine-java:8_server-jre_unlimited
    container_name: blade-product
    working_dir: /home/blade/product
    ports:
      - "8305:8305"
    volumes:
      - ./blade-product:/home/blade/product
    entrypoint: java -jar -Djava.security.egd=file:/dev/./urandom -server  -Xms1g -Xmx1g  blade-product.jar --spring.profiles.active=prod
    networks:
      - bluebook
      
  blade-order:
    image: anapsix/alpine-java:8_server-jre_unlimited
    container_name: blade-order
    working_dir: /home/blade/order
    ports:
      - "8805:8805"
    volumes:
      - ./blade-order:/home/blade/order
    entrypoint: java -jar -Djava.security.egd=file:/dev/./urandom -server -Xms1g -Xmx1g  blade-order.jar --spring.profiles.active=prod
    networks:
      - bluebook
      
      
   
      
networks:
  bluebook:


nginx 文件配置

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr"';

    access_log off;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    client_max_body_size  200m;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

	upstream gateway {
		server 192.168.1.8;
	}
	
	upstream auth{
		server 192.168.1.9:8100;
	}
	
	upstream log{
		server 192.168.1.8:8103;
	}
	
	upstream system{
		server 192.168.1.9:8106;
	}
	
	upstream user{
		server 192.168.1.9:8102;
	}
	
	upstream shop{
		server 192.168.1.8:8107;
	}
	
	upstream product{
		server 192.168.1.8:8305;
		
	}
	
	upstream order{
		server 192.168.1.8:8805;
	}
	
	upstream decorate{
		server 192.168.1.8:8605;
	}
	
	upstream usercenter{
		server 192.168.1.8:8705;
	}
	
	upstream resource{
		server 192.168.1.9:8010;
	}
	
	upstream discount{
		server 192.168.1.8:8109;
	}
	
	

	server {
	    listen 80;
	    server_name shop.bluebooknet.com;
		
		root /home/bluebook/dist;		
		
	    location / {
		   
		}

		location ^~/api {
           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_buffering off;
           rewrite ^/api/(.*)$ /$1 break;
           proxy_pass http://gateway;
		}

		location ^~/api/blade-auth {
           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_buffering off;
           rewrite ^/api/blade-auth/(.*)$ /$1 break;
           proxy_pass http://auth;
		}
		
		location ^~/api/blade-log {
           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_buffering off;
           rewrite ^/api/blade-log/(.*)$ /$1 break;
           proxy_pass http://log;
		}
		
		location ^~/api/blade-system {
           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_buffering off;
           rewrite ^/api/blade-system/(.*)$ /$1 break;
           proxy_pass http://system;
		}
		
		location ^~/api/blade-user {
           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_buffering off;
           rewrite ^/api/blade-user/(.*)$ /$1 break;
           proxy_pass http://user;
		}
		
		location ^~/api/blade-shop {
           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_buffering off;
           rewrite ^/api/blade-shop/(.*)$ /$1 break;
           proxy_pass http://shop;
		}
		
		location ^~/api/blade-product {
           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_buffering off;
           rewrite ^/api/blade-product/(.*)$ /$1 break;
           proxy_pass http://product;
		}
		
		location ^~/api/blade-order {
           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_buffering off;
           rewrite ^/api/blade-order/(.*)$ /$1 break;
           proxy_pass http://order;
		}
		
		location ^~/api/blade-decorate {
           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_buffering off;
           rewrite ^/api/blade-decorate/(.*)$ /$1 break;
           proxy_pass http://decorate;
		}
		
		location ^~/api/blade-usercenter {
           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_buffering off;
           rewrite ^/api/blade-usercenter/(.*)$ /$1 break;
           proxy_pass http://usercenter;
		}
		
		location ^~/api/blade-resource {
           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_buffering off;
           rewrite ^/api/blade-resource/(.*)$ /$1 break;
           proxy_pass http://resource;
		}
		
		location ^~/api/blade-discount {
           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_buffering off;
           rewrite ^/api/blade-discount/(.*)$ /$1 break;
           proxy_pass http://discount;
		}
	}
	
	
	

}


五、若有更多详细信息,请在下面提供。

1条回答
  • 2021-08-09 23:45

    blade-nginx是gateway的负载均衡接口,用于对外开放调用

    web-nginx是前端部署服务,内部自带gateway的反向代理

    作者追问:2021-08-23 17:53

    demo 中的web-nginx 配置是8000端口,blade-nginx 是88 端口, 不是很理解这个两个端口。难道nginx 不应该配置80 端口嘛?

    0 讨论(0)
提交回复