Nginx反向代理 网关路由转发

nginx反向代理

域名gulimall.com 通过映射关系对应 虚拟机地址ip(192.168.198.129)。虚拟机中的nginx服务器会监听gulimall.com:80的请求,一旦有请求就会反向代理至网关的地址 http://192.168.106.91:88。

nginx主要配置:http块,upstream 网关名, server代码块


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

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

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    upstream gulimall{
        server 192.168.106.91:88;
    }

	server {
		listen       80;
		server_name  gulimall.com;   //监听gulimall.com:80

		location / {
		   proxy_set_header Host $host;  //反向代理过程中可能会丢失Host头
		   proxy_pass gulimall;     //此处与upstream  一直
		}
	}
}

网关路由转发

网关接受到域名为gulimall.com的请求,就会通过路由规则转发至注册中心的微服务gulimall-product中http://192.168.106.91:10000

网关配置

spring:
  cloud:
    gateway:
      routes:
	  ....
	
	  //来自nginx的域名,要放到最后面。
        - id: gulimall_host_rout
          uri: lb://gulimall-product  #lb代表负载均衡
          predicates:
            - Host=**.gulimall.com    #Host

从而实现了请求从nginx->网关->微服务。

即http://gulimall.com:(80)/ --> http://192.168.106.91:10000/

你可能感兴趣的:(nginx,网关,nginx)