使用 nginx 实现在同一个微信公众号授权域名下访问正式版和测试版

2023-02-04 0 432

QQ社会公众号合作开发操作过程中要要在社会公众号前台增设页面许可搜索引擎、JSUSB搜索引擎和销售业务搜索引擎。比如说:h5.juejin.cn。

QQ的相匹配准则是全然相匹配,比如说: test.h5.juejin.cn 是不能透过的。

上面采用 nginx 逆向全权同时实现同一搜索引擎既能出访测试版,也能出访测试版。

nginx实用性server {listen 80;server_name h5.juejin.cn;### 推论与否重定向到确认页面 已经开始 start ========set $condiction noReferer;if ($http_referer){set $condiction ;## 关上QQ账号密码中的镜像时,QQ林美珠表明两个快照提示信息页面,点选 竭尽全力出访 就可以关上页面。这时 Referer = https://weixin110.qq.com/。if ($http_referer = “https://weixin110.qq.com/”) {set $condiction noReferer;## 忽视掉出访 /dev-tool 结尾的允诺if ($uri ~* “dev-tool(.*)”) {set $condiction “$condiction ignoreUri”;if ($http_cookie ~* “env=(.+?)(?=;|$)”) {####cookie中包涵“OWL”标记set $condiction $condiction isTest;if ($http_cookie ~* “ignoreConfirm=(.+?)(?=;|$)”) {#### cookie 中包含“首度出访OWL忽视提示信息页面”标记set $condiction $condiction ignoreConfirm;if ($condiction = noReferer isTest) {#### 任一1(关上页面)、 前提2(OWL)时重定向到提示信息页面rewrite ^/(.*) /dev-tool?redirect=$request_uri redirect;#### 推论与否重定向到证实页面 完结 end ========location / {#### 去除 cookie 中的“首度出访OWL忽视提示信息页面”标记add_header Set-Cookie ignoreConfirm=true;expires=Thu, 09 Dec 1970 06:05:42 GMT;path=/;#### 推论与否采用测试版 已经开始 start ========if ($http_cookie ~* “env=(.+?)(?=;|$)”) {# proxy_pass http://localhost:7001;proxy_pass http://localhost:11000;#### 推论与否采用测试版 完结 end ========root h5;try_files $uri $uri/ /index.html;add_header Cache-Control no-store;add_header Access-Control-Allow-Origin *;add_header Access-Control-Allow-Headers X-Requested-With;add_header Access-Control-Allow-Methods GET,POST,OPTIONS;# proxy_set_header Host $host:7001;#### QQH5xy_set_header X-Real-Port $remote_port;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#tion = /test {### 出访OWL,采用cookie标记出访的是OWL;cookie过期时间增设为1000年;add_header Set-Cookie env=test333;expires=Thu, 09 Dec 3021 06:05:42 GMT;path=/;### 首度开启OWL时增加“忽视提示信息页面”标记add_header Set-Cookie ignoreConfirm=true;expires=Thu, 09 Dec 3021 06:05:42 GMT;path=/;rewrite ^/(.*) / redirect;nginx 文件目录:

使用 nginx 实现在同一个微信公众号授权域名下访问正式版和测试版
关上网易新闻 查看精彩图片

dev-tool 文件夹目录结构:

注意在根目录 dev-tool 中还有文件夹 dev-tool

使用 nginx 实现在同一个微信公众号授权域名下访问正式版和测试版
关上网易新闻 查看精彩图片

index.html 文件内容见附录:index.html本地测试

所需软件: SwitchHosts

1. 将 h5.juejin.cn 解析到本地ip# 172.16.3.1 换成自己机器的ip,采用 127.0.0.1 也能,如果要支持手机出访,要指定 ip172.16.3.16 h5.juejin.cn

使用 nginx 实现在同一个微信公众号授权域名下访问正式版和测试版
关上网易新闻 查看精彩图片

2. 实用性 nginx

将 实用性 粘贴到 nginx.conf 文件中

3. 将页面放入对应目录中4。浏览器出访

测试版:http://h5.juejin.cn

测试版:http://h5.juejin.cn/test

附赠小知识nginx 中的 或 (||)、且(&&)运算

nginx 中没有或、且运算符,采用以下方式代替:

location /{set $condiction ;if ($http_referer = ){#### 关上页面或刷新页面时 Referer 表头为空set $condiction noReferer;if ($http_cookie ~* “env=(.+?)(?=;|$)”){set $condiction $condiction isTest;if ($condiction = noReferer isTest){#### 任一1(关上页面或刷新页面)、 前提2(OWL)时重定向到提示信息页面rewrite ^/(.*) /dev-tool?redirect=$request_uri redirect;推论允诺 cookie 中与否包涵OWL标记:location = /test{if ($http_cookie ~* “env=(.+?)(?=;|$)”){add_header Set-Cookie env=test1;expire=Tue, 09 Nov 2021 02:39:01 GMT;path=/;附录dev-tool/dev-tool/index.html 文件内容:charset=”UTF-8″>提示信息

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务