起初试了波官方ngrok的link,这个还是有点毒的,说是免费的,但没法配置自己的子域名(要购买),每次启动域名都是变化的.果断放弃
偶然发现小米球ngrok,试了一波还是不错的.
配置参考link
启动多个tunnel:
./ngrok -log=ngrok.log -config ngrok.conf start httptun httpstun
可以正常访问到nginx的index.html界面
在用postman发送http://yfxu.ngrok2.xiaomiqiu.cn/payed/notify?name=hello失败,看下日志
/mydata/nginx/logs$ cat error.log
2021/01/08 10:22:28 [error] 7#7: *66 open() “/usr/share/nginx/html/payed/notify” failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: “POST /payed/notify?name=hello HTTP/1.1”, host: “yfxu.ngrok2.xiaomiqiu.cn”
为何转到/usr/share/nginx/html/payed/notify这里了,看到host: “yfxu.ngrok2.xiaomiqiu.cn”,你应该明白了.这个域名没有监听,就默认去找静态文件了
那就再加个吧
listen 80;
server_name gulimall.com *.gulimall.com yfxu.ngrok2.xiaomiqiu.cn;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location /static/ {
root /usr/share/nginx/html;
}
location /payed/ {
proxy_set_header Host order.gulimall.com; #指定域名. 注:此处的$host为外网域名,不能为
proxy_pass http://gulimall; #在nginx.conf中设置的上游服务器组
}
location / {
proxy_set_header Host $host; #不让host丢失,要不网关没法根据host进行lb
proxy_pass http://gulimall; #在nginx.conf中设置的上游服务器组
}
这下就没有啥问题了,返回responsebody结果