{"id":823,"date":"2023-03-14T21:13:28","date_gmt":"2023-03-14T13:13:28","guid":{"rendered":"http:\/\/www.spiceandwolf.com.cn\/?p=823"},"modified":"2023-03-14T21:13:29","modified_gmt":"2023-03-14T13:13:29","slug":"nginx-debug","status":"publish","type":"post","link":"http:\/\/www.spiceandwolf.com.cn\/index.php\/nginx-debug\/","title":{"rendered":"nginx\u8c03\u8bd5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u65e5\u5fd7\u81ea\u5b9a\u4e49<\/h2>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5728\u65e5\u5fd7\u4e2d\u81ea\u5b9a\u4e49\u4e00\u4e9b\u8f93\u51fa\u53d8\u91cf\uff0c\u4ee5\u65b9\u4fbf\u5728\u51fa\u9519\u65f6\u66f4\u8be6\u7ec6\u7684\u4e86\u89e3\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http {\n    log_format geoproxy\n               '&#91;$time_local] $remote_addr '\n               '$realip_remote_addr $remote_user '\n               '$proxy_protocol_server_addr $proxy_protocol_server_port '\n               '$request_method $server_protocol '\n               '$scheme $server_name $url $status '\n               '$request_time $body_bytes_sent '\n               '$geoip_city_country_code3 $geoip_region '\n               '\"$geoip_city\" $http_x_forwarded_for '\n               '$upstream_status $upstream_response_time '\n               '\"$http_referer\" \"$http_user_agent\"';\n     # ...\n}<\/code><\/pre>\n\n\n\n<p>log_format\u914d\u7f6e\u4e2d\u5c06\u5f88\u591anginx\u7684\u5185\u7f6e\u53c2\u6570\u914d\u7f6e\u5230\u65e5\u5fd7\u4e2d\uff0c\u53c2\u6570\u5c31\u4e0d\u4e00\u4e00\u4f8b\u4e3e\u4e86\u3002\u800c\u65e5\u5fd7\u914d\u7f6e\u7684\u4f7f\u7528\u5219\u9700\u8981\u501f\u52a9\u4e8eaccess_log\u6307\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    access_log \/var\/log\/nginx\/access.log geoproxy;\n    # ...\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u914d\u7f6e\u9519\u8bef\u65e5\u5fd7<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>error_log \/var\/log\/nginx\/error.log warn;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6761\u6307\u4ee4\u5141\u8bb8\u5728\u9664\u4e86if\u4ee5\u5916\u7684\u6240\u6709\u4e0a\u4e0b\u6587\u4e2d\u914d\u7f6e\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u5199\u5165\u9519\u8bef\u65e5\u5fd7\u7684\u76ee\u5f55\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u9519\u8bef\u65e5\u5fd7\u7b49\u7ea7\uff0c\u9ed8\u8ba4\u4e3aerror\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bf7\u6c42\u8ffd\u6eaf<\/h2>\n\n\n\n<p>\u5f53\u4f60\u9700\u8981\u5c06\u90e8\u7f72\u7684\u5e94\u7528\u7684\u65e5\u5fd7\u548cnginx\u65e5\u5fd7\u5173\u8054\u8d77\u6765\u4ee5\u4fbf\u4e8e\u7406\u89e3\u7aef\u5230\u7aef\u8bf7\u6c42\u8fc7\u7a0b\u65f6\uff0c\u4e0b\u9762\u7684\u6307\u4ee4\u5c06\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>log_format trace '$remote_addr - $remote_user &#91;$time_local] '\n                 '\"$request\" $status $body_bytes_cent '\n                 '\"$http_referer\" \"$http_user_agent\" '\n                 '\"$http_x_forwarded_for\" $request_id';\nupstream backend {\n    server 10.0.0.42;\n}\nserver {\n    listen 80;\n    # Add the header X-Request-ID to the response to the client\n    add_header X-Request-ID $request_id;\n    location \/ {\n        proxy_pass http:\/\/backend;\n        # Send the header X-Request_ID to the appliction\n        proxy_set_header X-Request-ID $request_id;\n        access_log \/var\/log\/nginx\/access_trace.log trace;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u5728\u4e0a\u9762\u914d\u7f6e\u4e2d\u6211\u4eec\u901a\u8fc7$request_id\u53d8\u91cf\u5c06nginx-\u4e0a\u6e38\u670d\u52a1-\u5ba2\u6237\u7aef\u4e32\u8054\u8d77\u6765\uff0c\u901a\u8fc7\u8fd9\u4e2a\u53d8\u91cf\u6211\u4eec\u53ef\u4ee5\u8ddf\u8e2a\u8bf7\u6c42\u5728\u4e09\u8005\u4e2d\u7684\u5982\u4f55\u8fd0\u4f5c\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5728log_format trace\u4e2d\u914d\u7f6e\u4e86$request_id\u53d8\u91cf\uff0c\u6240\u4ee5\u8fd9\u4e2a\u53d8\u91cf\u5c06\u8bb0\u5f55\u5728nginx\u7684access_log\u65e5\u5fd7\u4e2d\uff1b\u540c\u6837\u6211\u4eec\u901a\u8fc7proxy_set_header\u6307\u4ee4\uff0c\u5728\u4ee3\u7406\u8bf7\u6c42\u4e2d\u52a0\u5165\u4e86\u503c\u4e3a$request_id\u7684X-Request-ID\u8bf7\u6c42\u5934\uff0c\u5e76\u901a\u8fc7add_header\u6307\u4ee4\u5c06X-Request-ID\u52a0\u5230\u4e86\u54cd\u5e94\u5934\u4fe1\u606f\u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e5\u5fd7\u81ea\u5b9a\u4e49 \u4f60\u53ef\u4ee5\u5728\u65e5\u5fd7\u4e2d\u81ea\u5b9a\u4e49\u4e00\u4e9b\u8f93\u51fa\u53d8\u91cf\uff0c\u4ee5\u65b9\u4fbf\u5728\u51fa\u9519\u65f6\u66f4\u8be6\u7ec6\u7684\u4e86\u89e3\u9519\u8bef\u4fe1\u606f\u3002 log_format\u914d\u7f6e\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-823","post","type-post","status-publish","format-standard","hentry","category-nginx"],"_links":{"self":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=823"}],"version-history":[{"count":4,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/823\/revisions"}],"predecessor-version":[{"id":827,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/823\/revisions\/827"}],"wp:attachment":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=823"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}