• 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;
    }

  • 相关阅读:
    iPhone6虽好,但也要借鉴这八个功能
    中小型企业商业智能平台的开发和实现(数据仓库、BI系统、真实项目实战)
    iOS开发入门教程_iOS开发视频教程
    零基础入门jQuery视频教程
    零基础3G Android移动开发就业培训
    请求库requesets库使用
    请求头加引号工具
    请求库urllib使用
    【Liunx】saltstack运维工具
    【Liunx】消息队列rabbitmp
  • 原文地址:https://www.cnblogs.com/normanlin/p/13960985.html
Copyright © 2020-2023  润新知