Carry の Blog Carry の Blog
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carry の Blog

好记性不如烂键盘
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 工作笔记

  • K8S

  • Systemd

  • Nginx

    • Nginx添加用户认证
    • 利用nginx+sftp实现一个可供用户下载的服务
    • nginx配置文件及模块
    • 通过脚本按天切割nginx的日志
    • nginx通过四层代理实现端口转发
    • NGINX基于cookie针对同一域名进行分流转发
    • nginx利用内置模块配置限速限流
    • 利用NGINX内置模块mirror进行流量复制等操作
    • 使用$remote_user字段记录访问NGINX的用户
    • 从NGINX自身配置文件中定义访问日志按时间切割
    • NGINX配置单独代理百度的sitemap文件
    • nginx配置微信小程序校验及其他
      • 1,微信小程序验证。
      • 2,返回字符串
      • 3,返回 json
      • 4,根据请求参数返回
        • 1,请求文件作为返回参数
        • 2,请求 url 作为返回
    • nginx配置gzip压缩
    • 由Nginx集中代理分散的PHP集群的实践
    • http状态码详解
    • OpenResty-1-13-6-2-新增ldap模块儿
    • 排查NGINX的open_file_cache导致发布后访问404的问题
    • 制作OpenResty-1-19-9-1的RPM包
    • nginx-proxy-managar使用笔记
    • Nginx 的端口复用:提升服务器并发能力
  • Supervisord

  • OpenLdap

  • OpenVPN

  • GitLab

  • Sshd

  • WebDev

  • Docker

  • Prometheus

  • Rclone

  • Iptables

  • Firewalld

  • Linux笔记
  • Nginx
Carry の Blog
2020-10-09
目录

nginx配置微信小程序校验及其他收藏(二丫讲梵)备查

# 1,微信小程序验证。

有时候在前端域名当中,接入微信小程序时需要一个 token 的验证,此处的配置可以直接用如下内容进行配置:

    location /37og2Z5TwR.txt {
        default_type    text/html;
        return 200 "6831c2a15d3d103c6a1ff356b22b5";
    }
1
2
3
4

此时访问域名,将会返回对应字符串内容。

# 2,返回字符串

当一个域名需要维护的时候,可以通过如下内容进行公示:

server {
    listen 80;
    server_name test.confluence.com;
    client_max_body_size 50m;
    client_body_buffer_size 1024k;
    location / {
        add_header Content-Type "text/html;charset=utf-8";
        return 200 "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>维护通知</title><style type=\"text/css\">.wrap{width:560px;margin:254px auto}.helloworld p{font:italic small-caps 13px/1.2em Arial}</style></head><body><div class=\"wrap\"><div class=\"helloworld\"><p>WIKI系统临时紧急维护, 稍后开放。非常抱歉影响您的使用。 04/24/2019 15:19, by OPS</p></div></div></body></html>";
    }
}
1
2
3
4
5
6
7
8
9
10

除了这些简单的返回方式,还有其他一些返回方式,这里统一进行一下汇总整理。

img

# 3,返回 json

配置如下:

    location ~ ^/get_info {
        default_type application/json;
        return 200 '{"status":"success","result":"hello world!"}';
    }
1
2
3
4

然后请求一下:

$ curl localhost/get_info | jq
{
  "status": "success",
  "result": "hello world!"
}
1
2
3
4
5

# 4,根据请求参数返回

# 1,请求文件作为返回参数

location ~ ^/return/(.*)_(\d+).html$ {
        default_type text/html;
        set $string $1;
        set $data   $2;
        return 200 $string:$data;
    }
1
2
3
4
5
6

测试效果:

$ curl localhost/return/test_01.html
test:01
1
2

# 2,请求 url 作为返回

location ~ ^/return/(.*)/(\d+)$ {
        default_type text/html;
        set $string $1;
        set $data $2;
        return 200 $string:$data;
    }
1
2
3
4
5
6

测试效果:

$ curl localhost/return/test/123
test:123
1
2
#nginx
上次更新: 4/24/2025

← NGINX配置单独代理百度的sitemap文件 nginx配置gzip压缩→

最近更新
01
tidb fast ddl
04-04
02
TiDB配置文件调优 原创
04-03
03
如何移除TiDB中的表分区 原创
04-03
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式