{"id":33295,"date":"2023-12-22T16:46:12","date_gmt":"2023-04-24T07:22:56","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/"},"modified":"2024-05-04T14:51:15","modified_gmt":"2024-05-04T06:51:15","slug":"%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/","title":{"rendered":"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4"},"content":{"rendered":"<h2>\u6982\u8ff0<\/h2>\n<p>\u4f7f\u7528Nginx\u548cgunicorn\u8fdb\u884c\u90e8\u7f72\u540e\uff0c\u90e8\u5206\u9875\u9762\u51fa\u73b0\u4e86&#8221;502 Bad Gateway&#8221;\u9519\u8bef\u3002\u4e3a\u4e86\u6682\u65f6\u663e\u793a\uff0c\u6211\u4eec\u5ef6\u957f\u4e86\u8d85\u65f6\u65f6\u95f4\u4ee5\u89e3\u51b3\u8be5\u95ee\u9898\u3002<\/p>\n<h2>\u73af\u5883<\/h2>\n<p>Python 3.9 \u548c Django 3.2<\/p>\n<h2>\u89e3\u51b3\u65b9\u6848 (ji\u011b ju\u00e9 \u00e0n)<\/h2>\n<p>\u5728 nginx.conf \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u53e5\u8bdd<br \/>\n\u5728 gunicorn \u91cd\u65b0\u542f\u52a8\u65f6\uff0c\u6dfb\u52a0\u547d\u4ee4\u884c\u53c2\u6570<\/p>\n<h2>\u64cd\u4f5c\u6b65\u9aa4 x\u00f9)<\/h2>\n<p>\u7f16\u8f91nginx.conf<\/p>\n<pre class=\"post-pre\"><code>sudo vi \/etc\/nginx\/nginx.conf\r\n<\/code><\/pre>\n<p>\u6839\u636e\u60c5\u51b5\u8fdb\u884c\u4ee5\u4e0b\u7684\u589e\u6dfb\uff08\u9ed8\u8ba4\u65f6\u95f4\u4e3a60\u79d2\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code>http{\r\n   ...\r\n   proxy_read_timeout 300;\r\n   proxy_connect_timeout 300;\r\n   proxy_send_timeout 300;\r\n   ...\r\n}\r\n<\/code><\/pre>\n<p>\u9488\u5bf9\u6bcf\u4e00\u4e2a\u8bbe\u5b9a\u503c<\/p>\n<p>proxy_connect_timeout<br \/>\n\u9759\u7684Web\u30b5\u30fc\u30d0 ( Nginx ) \u3068\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0 ( gunicorn ) \u3068\u306e\u63a5\u7d9a\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u79d2\u6570\u3092\u6307\u5b9a<br \/>\n\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u306b\u63a5\u7d9a\u8981\u6c42\u3092\u9001\u308a\u3001n\u79d2\u9593\u63a5\u7d9a\u3067\u304d\u306a\u3044\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059<br \/>\n\u3064\u307e\u308a\u300cn\u79d2\u7d4c\u3063\u3066\u3082 TCP\u30b3\u30cd\u30af\u30b7\u30e7\u30f3 \u304c\u78ba\u7acb\u3067\u304d\u306a\u3044\u5834\u5408\u306b\u30a8\u30e9\u30fc\u3092\u5410\u304f\u3088\u300d\u3068\u3044\u3046\u8a2d\u5b9a<\/p>\n<p>proxy_send_timeout<br \/>\n\u9759\u7684Web\u30b5\u30fc\u30d0 ( Nginx ) \u304b\u3089\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0 ( gunicorn ) \u3078\u306e\u30c7\u30fc\u30bf\u9001\u51fa\u306e\u63a5\u7d9a\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u79d2\u6570\u3092\u6307\u5b9a<br \/>\n\u3064\u307e\u308a\u300cTCP\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u78ba\u7acb\u5f8c\u3001n\u79d2\u7d4c\u3063\u3066\u3082 Nginx \u304b\u3089 gunicorn \u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3067\u304d\u306a\u3044\u5834\u5408\u306b\u30a8\u30e9\u30fc\u3092\u5410\u304f\u3088\u300d\u3068\u3044\u3046\u8a2d\u5b9a<\/p>\n<p>proxy_read_timeout<br \/>\n\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0 ( gunicorn ) \u304b\u3089 \u9759\u7684Web\u30b5\u30fc\u30d0 ( Nginx ) \u3078\u306e\u30c7\u30fc\u30bf\u9001\u51fa\u306e\u63a5\u7d9a\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u79d2\u6570\u3092\u6307\u5b9a<br \/>\n\u3064\u307e\u308a\u300cTCP\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u78ba\u7acb\u5f8c\u3001n\u79d2\u7d4c\u3063\u3066\u3082 gunicorn \u304b\u3089 Nginx \u3078\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u53d7\u4fe1\u3067\u304d\u306a\u3044\u5834\u5408\u306b\u30a8\u30e9\u30fc\u3092\u5410\u304f\u3088\u300d\u3068\u3044\u3046\u8a2d\u5b9a<\/p>\n<p>\u7531\u4e8e\u6211\u9047\u5230\u4e86\u67d0\u4e9b\u9875\u9762\u51fa\u73b0\u201c502 Bad Gateway\u201d\u9519\u8bef\uff0c\u6240\u4ee5\u6211\u53ea\u60f3\u5ef6\u957f\u63a5\u6536\u54cd\u5e94\u7684\u65f6\u95f4\uff0c\u56e0\u6b64\u6211\u8fdb\u884c\u4e86\u4ee5\u4e0b\u8bbe\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code>http{\r\n   ...\r\n   proxy_send_timeout 300;\r\n   ...\r\n}\r\n<\/code><\/pre>\n<p>\u8bf7\u91cd\u65b0\u542f\u52a8Nginx\u5e76\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>sudo systemctl restart nginx\r\n<\/code><\/pre>\n<p>\u63a5\u7740\u91cd\u65b0\u542f\u52a8 Gunicorn\uff08*\u9700\u8981\u5728\u547d\u4ee4\u884c\u53c2\u6570\u4e2d\u6dfb\u52a0 &#8211;timeout\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code># \u73fe\u5728\u8d77\u52d5\u4e2d\u306e gunicorn \u306e\u30dd\u30fc\u30c8\u756a\u53f7 (PID) \u3092\u78ba\u8a8d\r\nps aux | grep gunicorn\r\n\r\n# \u6307\u5b9a\u306e\u30dd\u30fc\u30c8\u756a\u53f7 (PID) \u3092 kill\r\nkill &lt;PID&gt;\r\n\r\n# gunicorn \u3092\u8d77\u52d5\r\ngunicorn config.wsgi:application --timeout 300\r\n<\/code><\/pre>\n<p>Gunicorn\u7684\u9ed8\u8ba4\u8d85\u65f6\u65f6\u95f4\u662f30\u79d2\uff0c\u56e0\u6b64\u8bf7\u6dfb\u52a0&#8211;timeout\u9009\u9879\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u4ee5\u540e\uff0c\u6211\u4eec\u5c06\u81f4\u529b\u4e8e\u63d0\u5347\u901f\u5ea6\uff0c\u4e0d\u518d\u53d1\u751f502\u9519\u8bef\uff01<\/p>\n<h2>\u53c2\u8003\u6587\u732e<\/h2>\n<p>\u8fd9\u4efd\u5907\u5fd8\u5f55\u662f\u6839\u636e\u4ee5\u4e0b\u4fe1\u606f\u4f5c\u4e3a\u53c2\u8003\u800c\u5236\u4f5c\u7684\uff0c\u975e\u5e38\u611f\u8c22\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8ff0 \u4f7f\u7528Nginx\u548cgunicorn\u8fdb\u884c\u90e8\u7f72\u540e\uff0c\u90e8\u5206\u9875\u9762\u51fa\u73b0\u4e86&#8221;502 Bad Gateway&#038; [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-33295","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u3010nginx-gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4-2\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4\" \/>\n<meta property=\"og:description\" content=\"\u6982\u8ff0 \u4f7f\u7528Nginx\u548cgunicorn\u8fdb\u884c\u90e8\u7f72\u540e\uff0c\u90e8\u5206\u9875\u9762\u51fa\u73b0\u4e86&#8221;502 Bad Gateway&amp; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u3010nginx-gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-24T07:22:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-04T06:51:15+00:00\" \/>\n<meta name=\"author\" content=\"\u6e05, \u626c\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u626c\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/\",\"name\":\"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-04-24T07:22:56+00:00\",\"dateModified\":\"2024-05-04T06:51:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\",\"name\":\"\u6e05, \u626c\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u626c\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u3010nginx-gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4-2\/","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4","og_description":"\u6982\u8ff0 \u4f7f\u7528Nginx\u548cgunicorn\u8fdb\u884c\u90e8\u7f72\u540e\uff0c\u90e8\u5206\u9875\u9762\u51fa\u73b0\u4e86&#8221;502 Bad Gateway& [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u3010nginx-gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4-2\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-04-24T07:22:56+00:00","article_modified_time":"2024-05-04T06:51:15+00:00","author":"\u6e05, \u626c","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u626c"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/","name":"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-04-24T07:22:56+00:00","dateModified":"2024-05-04T06:51:15+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u3010Nginx \/ gunicorn\u3011\u66f4\u6539\u8d85\u65f6\u65f6\u95f4"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461","name":"\u6e05, \u626c","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","caption":"\u6e05, \u626c"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90nginx-gunicorn%e3%80%91%e6%9b%b4%e6%94%b9%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4-2\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/33295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=33295"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/33295\/revisions"}],"predecessor-version":[{"id":98974,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/33295\/revisions\/98974"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=33295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=33295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=33295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}