openresty-nginx 线上conf分析

今天在某业务中看到一些比较有学习意义的nginx配置,故拿出来解析一下。

 

 

 

---------------------------------------------------------------------------------------------------

# -*- coding:utf-8 -*-

lua_shared_dict realtime_variable 16m; //ngx_lua模块中使用共享内存
lua_shared_dict lixian_zone_server_gim_schedule 100m; //ngx_lua模块中使用共享内存

server {
listen 80;
server_name 隐藏信息;

access_log logs/隐藏信息.access.log access_log_format;
error_log logs/隐藏信息.error.log warn;

default_type application/json; //默认传给浏览器json格式的响应
charset utf-8;
charset_types application/json; //模块在响应时能处理application/json文件

lua_code_cache on; //开启lua代码缓存,必开,否则性能差

set $project_lib_path 隐藏信息; //设置变量

location ~* ^隐藏信息{
if ($request_method = 'OPTIONS') {  //添加跨域请求,通常其他域名调用该域名时,会提前发出options的请求信息,如果域名在允许名单中,就返回204表示可以跨域。
add_header Access-Control-Allow-Origin "$http_origin";
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
return 204;
}
access_by_lua_file $project_lib_path/lua/access_check.lua; //access_by_lua在请求访问阶段处理,用于访问控制
content_by_lua_file $project_lib_path/lua/tasks/entry.lua; //content_by_lua是内容处理器,接受请求并输出响应
log_by_lua_file /usr/local/openresty/nginx/conf/http_status_lua/record.lua; //lua日志配置
}

location ~* ^隐藏信息 {

if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin "$http_origin";
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
return 204;
}
access_by_lua_file $project_lib_path/lua/access_check.lua;
content_by_lua_file $project_lib_path/lua/tasks/entry.lua;
log_by_lua_file /usr/local/openresty/nginx/conf/http_status_lua/record.lua;
}

.

.
.

location ~* ^ 隐藏信息{

if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin "$http_origin";
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
return 204;
}
content_by_lua_file $project_lib_path/lua/search/entry.lua;
}


location ^~ 隐藏信息 {
proxy_pass http:/隐藏信息:8908/;
proxy_set_header Host 隐藏信息;   //转发并以某个域名取请求后端的8908
}

 

 

include monitor.conf;
}

posted @ 2020-11-11 21:13  Normanlin  阅读(287)  评论(0编辑  收藏  举报