内网穿透原理和应用

内网穿透软件

natapp

花生壳

原理

外网访问内网穿透服务商,服务商将域名代理给本地机器,本地机器通过域名解析映射成ip地址
比如配置了nginx,通过解析成的ip地址,代理给上游服务(upstream),upstream代理给后端项目网关

内网穿透配置

xctm3b.natappfree.cc 代理本地机器order.gulimall.com:80

windows下配置hosts

#本地主机映射到虚拟机地址(nginx地址)
192.168.182.130 order.gulimall.com

linux 下 nginx.conf

http{
	#负载均衡上游服务器,代理给后端网关
	upstream gulimall{
	#gateway
	server 192.168.0.122:88;		
    }
    
	server {
	    listen       80;
	    # xctm3b.natappfree.cc 为内网穿透商地址
	    server_name  gulimall.com *.gulimall.com xctm3b.natappfree.cc;
	
	    #charset koi8-r;
	    #access_log  /var/log/nginx/log/host.access.log  main;
	    
	    # 静态资源
	    location /static/ {
	        root   /usr/share/nginx/html;
	    }
	    
	    # 精确路由并指定host为order.gulimall.com
	    location /payed/ {
	        proxy_set_header Host order.gulimall.com;
	        #负载均衡上游服务器,代理给后端网关
	        proxy_pass http://gulimall;
	    }
	
	    # 谷粒商城代理地址
	    location / {
	        proxy_set_header Host $host;
	        proxy_pass http://gulimall;
	    }
	}
}

后端网关配置yml

spring:
  application:
    name: gulimall-gateway
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    gateway:
      routes:
       #=============================域名路由===============================
        - id: gulimall_order_route
          uri: lb://gulimall-order
          predicates:
            - Host=order.gulimall.com
server:
  port: 88

order微服务

@Slf4j
@RestController
public class OrderPayedListener {
    @PostMapping("/payed/notify")
    public String handleAlipayed(HttpServletRequest request){
        Map<String, String[]> parameterMap = request.getParameterMap();
        log.info("支付宝通知成功。。。。。。。。。。。", parameterMap);
        return "success";
    }
}

你可能感兴趣的:(nginx,服务器,java,运维)