{"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
\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
\u6211\u4eec\u5148\u6765\u770b\u7ef4\u57fa\u767e\u79d1\u4e0a\u7684\u89e3\u91ca\uff1a<\/p>\n
\n502 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
<?<\/span>php<\/span><\/code><\/li>
echo date<\/span>(<\/span>'h:i:s'<\/span>)<\/span> <\/span>.<\/span> <\/span>\"<br \/>\"<\/span>;<\/span><\/code><\/li>
<\/code><\/li>
\/\/\u6682\u505c 10 \u79d2<\/span><\/code><\/li>
sleep<\/span>(<\/span>40<\/span>);<\/span><\/code><\/li>
<\/code><\/li>
\/\/\u91cd\u65b0\u5f00\u59cb<\/span><\/code><\/li>
echo date<\/span>(<\/span>'h:i:s'<\/span>);<\/span><\/code><\/li>
<\/code><\/li>
?><\/span><\/code><\/li><\/ol><\/pre>\n
nginx\u914d\u7f6e<\/p>\n
location <\/span>\/<\/span> <\/span>{<\/span><\/code><\/li>
proxy_pass http<\/span>:<\/span>\/\/php;<\/span><\/code><\/li>
proxy_connect_timeout <\/span>30<\/span>;<\/span><\/code><\/li>
proxy_send_timeout <\/span>30<\/span>;<\/span><\/code><\/li>
proxy_read_timeout <\/span>30<\/span>;<\/span><\/code><\/li>
}<\/span><\/code><\/li><\/ol><\/pre>\n
\u7ed3\u679c\uff1a<\/p>\n
[<\/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>
<!<\/span>DOCTYPE HTML PUBLIC <\/span>\"-\/\/IETF\/\/DTD HTML 2.0\/\/EN\"<\/span>><\/span><\/code><\/li>
<html><\/span><\/code><\/li>
<head><title><\/span>504<\/span> <\/span>Gateway<\/span> <\/span>Time<\/span>-<\/span>out<\/span><<\/span>\/title><\/<\/span>head<\/span>><\/span><\/code><\/li>
<<\/span>body bgcolor<\/span>=<\/span>\"white\"<\/span>><\/span><\/code><\/li>
<h1><\/span>504<\/span> <\/span>Gateway<\/span> <\/span>Time<\/span>-<\/span>out<\/span><\/<\/span>h1<\/span>><\/span><\/code><\/li>
<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>
Please<\/span> report <\/span>this<\/span> message <\/span>and<\/span> include the following information to us<\/span>.<<\/span>br<\/span>\/><\/span><\/code><\/li>
Thank<\/span> you very much<\/span>!<\/<\/span>p<\/span>><\/span><\/code><\/li>
<table><\/span><\/code><\/li>
\u6b64\u5904\u7701\u7565\u2026\u2026<\/span><\/code><\/li>
<\/code><\/li>
real <\/span>0m30.005s<\/span><\/code><\/li>
user <\/span>0m0.001s<\/span><\/code><\/li>
sys <\/span>0m0.004s<\/span><\/code><\/li><\/ol><\/pre>\n
\u6a21\u62dfnginx502\u9519\u8bef<\/h2>\n
nginx\u914d\u7f6e<\/p>\n
proxy_pass http<\/span>:<\/span>\/\/10.127.130.41:8900;<\/span><\/code><\/li>
#nginx\u548c\u540e\u7aefupstream\u65e0\u6cd5\u901a\u4fe1<\/span><\/code><\/li><\/ol><\/pre>\n
\u7ed3\u679c\uff1a<\/p>\n
[<\/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>
<!<\/span>DOCTYPE HTML PUBLIC <\/span>\"-\/\/IETF\/\/DTD HTML 2.0\/\/EN\"<\/span>><\/span><\/code><\/li>
<html><\/span><\/code><\/li>
<head><title><\/span>502<\/span> <\/span>Bad<\/span> <\/span>Gateway<\/span><<\/span>\/title><\/<\/span>head<\/span>><\/span><\/code><\/li>