{"id":871,"date":"2016-06-06T23:11:48","date_gmt":"2016-06-06T15:11:48","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=871"},"modified":"2016-06-06T23:11:48","modified_gmt":"2016-06-06T15:11:48","slug":"nginx-502-504","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2016\/06\/nginx-502-504\/","title":{"rendered":"nginx\u7684502\u62a5\u9519\u548c504\u62a5\u9519\u6709\u4ec0\u4e48\u533a\u522b"},"content":{"rendered":"

nginx\u7684502\u62a5\u9519\u548c504\u62a5\u9519\u6709\u4ec0\u4e48\u533a\u522b\uff1f
\n<\/p>\n

\u5f15\u5165<\/h2>\n

\u8fd8\u771f\u662f\u4e2a\u65e0\u804a\u7684\u8bdd\u9898\uff0c\u4e0d\u8fc7\u8fd9\u662f\u4e00\u4e2a\u9762\u8bd5\u9898\u3002\u8003\u5bdf\u4f60\u5bf9Nginx\u5de5\u4f5c\u673a\u5236\u7684\u4e86\u89e3\u3002<\/p>\n

\u5206\u6790<\/h2>\n

\u6211\u4eec\u5148\u6765\u770b\u7ef4\u57fa\u767e\u79d1\u4e0a\u7684\u89e3\u91ca\uff1a<\/p>\n

\n

502 Bad Gateway<\/strong>
\n The server was acting as a gateway or proxy and received an invalid response from the upstream server.
\n 504 Gateway Timeout<\/strong>
\n The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.<\/p>\n<\/blockquote>\n

\u597d\u4e86\uff0c\u770b\u5b8c\u89e3\u91ca\uff0c\u7b54\u6848\u4e5f\u51fa\u6765\u4e86\u3002<\/p>\n

502\u6307\u7684\u662f\u540e\u7aef\u670d\u52a1\u5668\u65e0\u54cd\u5e94\uff0c\u538b\u6839\u6ca1\u6536\u5230\u6709\u6548\u7684\u53cd\u9988\u3002
\n504\u6307\u7684\u662f\u540e\u7aef\u670d\u52a1\u5668\u6ca1\u6709\u53ca\u65f6\u54cd\u5e94\uff0c\u4e5f\u5c31\u662f\u8bf4\u671f\u5f85\u67d0\u4e2a\u56de\u5e94\uff0c\u4f46\u7b49\u5f85\u65f6\u95f4\u8fc7\u957f\uff0c\u8d85\u65f6<\/p>\n

\u6a21\u62df\u4e00\u4e2anginx504\u62a5\u9519<\/h2>\n

php\u4ee3\u7801\uff1a<\/p>\n

  1. <?<\/span>php<\/span><\/code><\/li>
  2. echo date<\/span>(<\/span>'h:i:s'<\/span>)<\/span> <\/span>.<\/span> <\/span>\"<br \/>\"<\/span>;<\/span><\/code><\/li>
  3. <\/code><\/li>
  4. \/\/\u6682\u505c 10 \u79d2<\/span><\/code><\/li>
  5. sleep<\/span>(<\/span>40<\/span>);<\/span><\/code><\/li>
  6. <\/code><\/li>
  7. \/\/\u91cd\u65b0\u5f00\u59cb<\/span><\/code><\/li>
  8. echo date<\/span>(<\/span>'h:i:s'<\/span>);<\/span><\/code><\/li>
  9. <\/code><\/li>
  10. ?><\/span><\/code><\/li><\/ol><\/pre>\n

    nginx\u914d\u7f6e<\/p>\n

    1. location <\/span>\/<\/span> <\/span>{<\/span><\/code><\/li>
    2. proxy_pass http<\/span>:<\/span>\/\/php;<\/span><\/code><\/li>
    3. proxy_connect_timeout <\/span>30<\/span>;<\/span><\/code><\/li>
    4. proxy_send_timeout <\/span>30<\/span>;<\/span><\/code><\/li>
    5. proxy_read_timeout <\/span>30<\/span>;<\/span><\/code><\/li>
    6. }<\/span><\/code><\/li><\/ol><\/pre>\n

      \u7ed3\u679c\uff1a<\/p>\n

      1. [<\/span>root@BJ<\/span>-<\/span>BX<\/span>-<\/span>130<\/span>-<\/span>27<\/span> <\/span>~]#<\/span>time curl <\/span>-<\/span>H <\/span>\"Host:ipcpu.com\"<\/span> http<\/span>:<\/span>\/\/127.0.0.1\/testphp.php<\/span><\/code><\/li>
      2. <!<\/span>DOCTYPE HTML PUBLIC <\/span>\"-\/\/IETF\/\/DTD HTML 2.0\/\/EN\"<\/span>><\/span><\/code><\/li>
      3. <html><\/span><\/code><\/li>
      4. <head><title><\/span>504<\/span> <\/span>Gateway<\/span> <\/span>Time<\/span>-<\/span>out<\/span><<\/span>\/title><\/<\/span>head<\/span>><\/span><\/code><\/li>
      5. <<\/span>body bgcolor<\/span>=<\/span>\"white\"<\/span>><\/span><\/code><\/li>
      6. <h1><\/span>504<\/span> <\/span>Gateway<\/span> <\/span>Time<\/span>-<\/span>out<\/span><\/<\/span>h1<\/span>><\/span><\/code><\/li>
      7. <p><\/span>The<\/span> gateway did <\/span>not<\/span> receive a timely response <\/span>from<\/span> the upstream server <\/span>or<\/span> application<\/span>.<\/span> <\/span>Sorry<\/span> <\/span>for<\/span> the inconvenience<\/span>.<<\/span>br<\/span>\/><\/span><\/code><\/li>
      8. Please<\/span> report <\/span>this<\/span> message <\/span>and<\/span> include the following information to us<\/span>.<<\/span>br<\/span>\/><\/span><\/code><\/li>
      9. Thank<\/span> you very much<\/span>!<\/<\/span>p<\/span>><\/span><\/code><\/li>
      10. <table><\/span><\/code><\/li>
      11. \u6b64\u5904\u7701\u7565\u2026\u2026<\/span><\/code><\/li>
      12. <\/code><\/li>
      13. real <\/span>0m30.005s<\/span><\/code><\/li>
      14. user <\/span>0m0.001s<\/span><\/code><\/li>
      15. sys <\/span>0m0.004s<\/span><\/code><\/li><\/ol><\/pre>\n

        \u6a21\u62dfnginx502\u9519\u8bef<\/h2>\n

        nginx\u914d\u7f6e<\/p>\n

        1. proxy_pass http<\/span>:<\/span>\/\/10.127.130.41:8900;<\/span><\/code><\/li>
        2. #nginx\u548c\u540e\u7aefupstream\u65e0\u6cd5\u901a\u4fe1<\/span><\/code><\/li><\/ol><\/pre>\n

          \u7ed3\u679c\uff1a<\/p>\n

          1. [<\/span>root@BJ<\/span>-<\/span>BX<\/span>-<\/span>130<\/span>-<\/span>27<\/span> <\/span>~]#<\/span>time curl <\/span>-<\/span>H <\/span>\"Host:ipcpu.com\"<\/span> http<\/span>:<\/span>\/\/127.0.0.1\/<\/span><\/code><\/li>
          2. <!<\/span>DOCTYPE HTML PUBLIC <\/span>\"-\/\/IETF\/\/DTD HTML 2.0\/\/EN\"<\/span>><\/span><\/code><\/li>
          3. <html><\/span><\/code><\/li>
          4. <head><title><\/span>502<\/span> <\/span>Bad<\/span> <\/span>Gateway<\/span><<\/span>\/title><\/<\/span>head<\/span>><\/span><\/code><\/li>
          5. <<\/span>body bgcolor<\/span>=<\/span>\"white\"<\/span>><\/span><\/code><\/li>
          6. <h1><\/span>502<\/span> <\/span>Bad<\/span> <\/span>Gateway<\/span><\/<\/span>h1<\/span>><\/span><\/code><\/li>
          7. <p><\/span>The<\/span> proxy server received an invalid response <\/span>from<\/span> an upstream server<\/span>.<\/span> <\/span>Sorry<\/span> <\/span>for<\/span> the inconvenience<\/span>.<<\/span>br<\/span>\/><\/span><\/code><\/li>
          8. Please<\/span> report <\/span>this<\/span> message <\/span>and<\/span> include the following information to us<\/span>.<<\/span>br<\/span>\/><\/span><\/code><\/li>
          9. Thank<\/span> you very much<\/span>!<\/<\/span>p<\/span>><\/span><\/code><\/li>
          10. <table><\/span><\/code><\/li>
          11. \u6b64\u5904\u7701\u7565\u2026\u2026<\/span><\/code><\/li>
          12. <\/code><\/li>
          13. real <\/span>0m3.006s<\/span><\/code><\/li>
          14. user <\/span>0m0.002s<\/span><\/code><\/li>
          15. sys <\/span>0m0.002s<\/span><\/code><\/li><\/ol><\/pre>\n

            \u7ed3\u8bba<\/h2>\n

            \u901a\u8fc7\u4e0a\u9762\u4e24\u4e2a\u5b9e\u9a8c\uff0c\u662f\u4e0d\u662f\u66f4\u6e05\u6670\u4e86\uff1f
            \n\u901a\u4fd7\u4e00\u4e9b\uff0c502\u662f\u540e\u7aef\u6b7b\u4e86\uff0c\u8fde\u4e0d\u4e0a\uff08\u53ef\u80fd\u65e0\u6cd5\u5efa\u7acbTCP\u8fde\u63a5\uff09 \uff0c504\u662f\u540e\u7aef\u6d3b\u7740\uff0c\u4f46\u6ca1\u7ed9\u6211\u56de\u5e94\uff08\u81f3\u5c11TCP\u8fde\u63a5\u5df2\u7ecf\u5efa\u7acb\uff09\u3002<\/p>\n

            \u5982\u4f55\u89e3\u9664\u9519\u8bef<\/h2>\n

            502\u7684\u60c5\u51b5\u9700\u8981\u68c0\u67e5\u540e\u7aef\u670d\u52a1\u5668\u72b6\u6001\u3002
            \n504\u7684\u60c5\u51b5\u9700\u8981\u68c0\u67e5\u540e\u7aef\u670d\u52a1\u5668\u54cd\u5e94\u60c5\u51b5\uff0c\u548cnginx\u8bbe\u7f6e\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/p>\n

            \u53c2\u8003\u8d44\u6599<\/h2>\n

            http:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_status_codes<\/a><\/p>\n

            \u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » nginx\u7684502\u62a5\u9519\u548c504\u62a5\u9519\u6709\u4ec0\u4e48\u533a\u522b<\/a><\/p>","protected":false},"excerpt":{"rendered":"

            nginx\u7684502\u62a5\u9519\u548c504\u62a5\u9519\u6709\u4ec0\u4e48\u533a\u522b\uff1f \u5f15\u5165 \u8fd8\u771f\u662f\u4e2a\u65e0\u804a\u7684\u8bdd\u9898\uff0c\u4e0d\u8fc7\u8fd9\u662f\u4e00\u4e2a\u9762\u8bd5\u9898\u3002\u8003\u5bdf\u4f60\u5bf9Nginx\u5de5\u4f5c\u673a\u5236\u7684\u4e86\u89e3\u3002 \u5206\u6790 \u6211\u4eec\u5148\u6765\u770b\u7ef4\u57fa\u767e\u79d1\u4e0a\u7684\u89e3\u91ca\uff1a 502 Bad Gateway The server was acting as a gateway or proxy and received an invalid response from the upstream server. 504 Gateway Timeout The server was acting as a gateway or proxy and did not receive a timely response from the upstream server. \u597d\u4e86\uff0c\u770b\u5b8c\u89e3\u91ca\uff0c\u7b54\u6848\u4e5f\u51fa\u6765\u4e86\u3002 502\u6307\u7684\u662f\u540e\u7aef\u670d\u52a1\u5668\u65e0\u54cd\u5e94\uff0c\u538b\u6839\u6ca1\u6536\u5230\u6709\u6548\u7684\u53cd\u9988\u3002 504\u6307\u7684\u662f\u540e\u7aef\u670d\u52a1\u5668\u6ca1\u6709\u53ca\u65f6\u54cd\u5e94\uff0c\u4e5f\u5c31\u662f\u8bf4\u671f\u5f85\u67d0\u4e2a\u56de\u5e94\uff0c\u4f46\u7b49\u5f85\u65f6\u95f4\u8fc7\u957f\uff0c\u8d85\u65f6 \u6a21\u62df\u4e00\u4e2anginx504\u62a5\u9519 php\u4ee3\u7801\uff1a <?phpecho […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[14],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/871"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=871"}],"version-history":[{"count":0,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/871\/revisions"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}