如何在nginx代理文件中编写日志语句?

时间:2017-11-15 09:16:39

标签: java nginx logging proxy cors

我正在使用nginx代理进行条件代理。所以我正在编辑nginx.conf文件。 我基本上是为任何传入的 OPTIONS 方法添加额外的标题。

我想在代码执行时打印日志吗?

      location /agentservice/{

                    # OPTIONS indicates a CORS pre-flight request
                    # OPTIONS (pre-flight) request from allowed
                    # CORS domain. return response directly

                    if ($request_method = 'OPTIONS') {
                            **log("I want to print this log to log files")** // I want to print this/above statement in log files.  
                            add_header X-debug-message "Inside OPTIONS" ;
                            add_header 'Access-Control-Allow-Origin' *;
                            add_header 'Access-Control-Allow-Credentials' 'true';
                            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
                            add_header 'Access-Control-Allow-Headers'  'Origin,Content-Type,Accept,Authorization';
                            add_header Content-Length 0;
                            add_header Content-Type application/json;
                            return 204;
                    }
      }

我怎样才能做到这一点?

0 个答案:

没有答案