Nginx 实现txt配置接口以及响应 – 默认map模块

2023-09-14 08:16:00 浏览数 (1)

引入的文件如下:

代码语言:javascript复制
/diy/abc "{"name":1}";
/diy/bcd "{"name":999}";
/logout/11 "123";
/logout/22 "{"name":9199}";

Nginx配置

代码语言:javascript复制
http {
   

    map $request_uri $response {
    	include /Users/zanglikun/Desktop/urlAndResponse.txt;
	default "";
    }


    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        access_log  /Users/zanglikun/Desktop/nginxlog.log  mylog;

        location / {
            root   html;
            index  index.html index.htm;

            if ($response = "") {
		return 404;
            }
            add_header Content-Type application/json;
            return 200 $response;

        }


    include servers/*;
}

尽管结果是

0 人点赞