{"id":183,"date":"2016-06-08T17:55:06","date_gmt":"2016-06-08T09:55:06","guid":{"rendered":"http:\/\/www.shenmdyw.com\/?p=183"},"modified":"2016-06-16T09:08:12","modified_gmt":"2016-06-16T01:08:12","slug":"nginxphp","status":"publish","type":"post","link":"http:\/\/www.shenmdyw.com\/index.php\/2016\/06\/08\/nginxphp\/","title":{"rendered":"\u3010\u8f6c\u8f7d\u3011windows\u4e0bnginx+fastcgi\u4e0d\u80fd\u4f7f\u7528file_get_contents\/curl\/fopen\u7684\u539f\u56e0"},"content":{"rendered":"<p>\u8fd9\u4e24\u5929\u4e00\u76f4\u5728\u641e<span lang=\"EN-US\">windows<\/span>\u4e0b<span lang=\"EN-US\">nginx+fastcgi<\/span>\u7684<span lang=\"EN-US\">file_get_contents<\/span>\u8bf7\u6c42\u3002\u6211\u60f3\uff0c\u5f88\u591a\u540c\u5b66\u90fd\u9047\u5230\u5f53<span lang=\"EN-US\">file_get_contents<\/span>\u8bf7\u6c42\u5916\u7f51\u7684<span lang=\"EN-US\">http\/https<\/span>\u7684<span lang=\"EN-US\">php<\/span>\u6587\u4ef6\u65f6\u6beb\u65e0\u538b\u529b\uff0c\u6bd4\u5982<span lang=\"EN-US\">echo file_get_contents(\u2018<a href=\"http:\/\/www.baidu.com\/\" rel=\"nofollow\">http:\/\/www.baidu.com<\/a>\u2019)<\/span>\uff0c\u5b83\u4f1a\u663e\u793a\u767e\u5ea6\u7684\u9875\u9762\u3002\u4f46\u5f53\u4f60\u8bf7\u6c42<span lang=\"EN-US\">localhost\/127.0.0.1<\/span>\u672c\u5730\u7f51\u7edc\u7684<span lang=\"EN-US\">php<\/span>\u670d\u52a1\u65f6\u5374\u4e00\u76f4\u662f<span lang=\"EN-US\">timeout<\/span>\uff0c\u65e0\u8bba\u4f60\u5c06\u8bf7\u6c42\u65f6\u95f4\u548c\u811a\u672c\u8fd0\u884c\u65f6\u95f4\u591a\u957f\u90fd\u65e0\u6cd5\u8fd4\u56de\u6570\u636e\uff0c\u5982<span lang=\"EN-US\">file_get_contents(\u2018http:\/\/localhost\/phpinfo.php\u2019)<\/span>\u3002\u7136\u800c\u5f53\u4f60\u5c1d\u8bd5\u8bf7\u6c42<span lang=\"EN-US\">html<\/span>\u8fd9\u6837\u7684\u9759\u6001\u6587\u4ef6\u65f6\u5374\u5b8c\u5168\u6ca1\u6709\u95ee\u9898\u3002\u662f\u4ec0\u4e48\u539f\u56e0\u5462\uff1f\uff01<!--more--><\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u77e5\u9053<span lang=\"EN-US\">file_get_contents\/curl\/fopen<\/span>\u6253\u5f00\u4e00\u4e2a\u57fa\u4e8e<span lang=\"EN-US\">tcp\/ip<\/span>\u7684<span lang=\"EN-US\">http<\/span>\u8bf7\u6c42\u65f6\uff0c\u8bf7\u6c42\u6570\u636e\u53d1\u9001\u5230<span lang=\"EN-US\">nginx<\/span>\uff0c\u800c<span lang=\"EN-US\">nginx<\/span>\u5219\u59d4\u6258\u7ed9<span lang=\"EN-US\">php-cgi(fastcgi)<\/span>\u5904\u7406<span lang=\"EN-US\">php<\/span>\u6587\u4ef6\uff0c\u4e00\u822c\u60c5\u51b5<span lang=\"EN-US\">fastcgi<\/span>\u5904\u7406\u5b8c\u4e00\u4e2a<span lang=\"EN-US\">php<\/span>\u8bf7\u6c42\u540e\u4f1a\u9a6c\u4e0a\u91ca\u653e\u7ed3\u675f\u4fe1\u53f7\uff0c\u7b49\u5f85\u4e0b\u4e00\u4e2a\u5904\u7406\u8bf7\u6c42\uff08\u5f53\u7136\u4e5f\u6709\u7a0b\u5e8f\u5047\u6b7b\uff0c\u4e00\u76f4\u5360\u7528\u8d44\u6e90\u7684\u60c5\u51b5\uff09\u3002\u6253\u5f00<span lang=\"EN-US\">nginx.conf<\/span>\uff0c\u6211\u4eec\u770b\u5230\u4e0b\u9762\u8fd9\u4e00\u884c\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>location ~ \\.php {<br \/>\nfastcgi_pass 127.0.0.1:9000;<br \/>\nfastcgi_index index.php;<br \/>\nfastcgi_param SCRIPT_FILENAME d:\/www\/htdocs$fastcgi_script_name;<br \/>\ninclude fastcgi_params;<br \/>\n}<\/p>\n<p>\u4e0a\u9762\u5df2\u7ecf\u6e05\u695a\u5730\u770b\u5230\uff0c\u6240\u6709\u4f7f\u7528<span lang=\"EN-US\">php<\/span>\u7ed3\u5c3e\u7684\u6587\u4ef6\u90fd\u7ecf\u8fc7<span lang=\"EN-US\">fastcgi<\/span>\u5904\u7406\uff0c\u800c\u5728<span lang=\"EN-US\">php.ini<\/span>\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u4e5f\u6709\u4e00\u53e5\uff1a<\/p>\n<p>cgi.force_redirect = 1<\/p>\n<p>\u8868\u660e\uff0c\u6240\u6709<span lang=\"EN-US\">php<\/span>\u7a0b\u5e8f\u5b89\u5168\u5730\u5f3a\u5236\u8f6c\u5411\u4ea4\u7ed9<span lang=\"EN-US\">cgi<\/span>\u5904\u7406\u3002<\/p>\n<p>\u4f46\u5728<span lang=\"EN-US\">windows<\/span>\u4e2d\uff0c\u672c\u5730<span lang=\"EN-US\">127.0.0.1:9000<\/span>\u600e\u6837\u4e0e<span lang=\"EN-US\">php-cgi<\/span>\u8054\u7cfb\u7684\u5462\uff1f\uff01\u7b54\u6848\u662f\u589e\u52a0\u4e00\u4e2a<span lang=\"EN-US\">php-cgi<\/span>\u8fdb\u7a0b\uff0c\u7528\u5b83\u6765\u76d1\u542c<span lang=\"EN-US\">127.0.0.1:9000<\/span>\u3002\u901a\u8fc7\u63a7\u5236\u5668\u547d\u4ee4\uff1a<\/p>\n<p>RunHiddenConsole.exe D:\/www\/php\/php-cgi.exe -b 127.0.0.1:9000 -c C:\/WINDOWS\/php.ini<\/p>\n<p>\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u542f\u52a8<span lang=\"EN-US\">windows<\/span>\u65f6\uff0c\u5f00\u542f\u4e00\u4e2a<span lang=\"EN-US\">php-cgi.exe<\/span>\u8fdb\u7a0b\u76d1\u542c\u6765\u81ea<span lang=\"EN-US\">127.0.0.1:9000 <\/span>\u7684\u8bf7\u6c42\u3002\u5728<span lang=\"EN-US\">dos<\/span>\u547d\u4ee4\u4e0b\u6253\u5f00<span lang=\"EN-US\">netstat \u2013a<\/span>\u5c31\u53ef\u4ee5\u770b\u5230\u672c\u5730\u8ba1\u7b97\u673a\u4e0b\u7684<span lang=\"EN-US\">9000<\/span>\u7aef\u53e3\u5904\u4e8e<span lang=\"EN-US\">listening<\/span>\u72b6\u6001\uff08\u4e5f\u5c31\u662f\u7a7a\u7f6e\uff0c\u5982\u679c\u6ca1\u6709\u53d1\u9001\u4efb\u4f55\u8bf7\u6c42\u7684\u8bdd\uff09\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u8be5\u8bf4\u8bf4\u5728<span lang=\"EN-US\">php<\/span>\u4e2d\u4f7f\u7528<span lang=\"EN-US\">file_get_contents()<\/span>\u3001<span lang=\"EN-US\">curl()<\/span>\u3001<span lang=\"EN-US\">fopen()<\/span>\u51fd\u6570\u8bbf\u95ee<span lang=\"EN-US\">localhost<\/span>\u65f6\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u8fd4\u56de\u7ed3\u679c\u3002\u6211\u4eec\u518d\u6765\u8bd5\u9a8c\u5728<span lang=\"EN-US\">index.php<\/span>\u4e2d\u52a0\u5165<span lang=\"EN-US\">file_get_contents(\u2018<a href=\"http:\/\/127.0.0.1\/phpinfo.php')%E8%AF%AD%E5%8F%A5%E5%90%91phpinfo.php\" rel=\"nofollow\">http:\/\/127.0.0.1\/phpinfo.php\u2019)<span lang=\"EN-US\">\u8bed\u53e5\u5411<\/span>phpinfo.php<\/a><\/span>\u53d1\u9001\u4e00\u4e2a\u8bf7\u6c42\uff0c\u8fd9\u65f6\u6d4f\u89c8\u5668\u4e2d\u7684\u72b6\u6001\u6307\u793a\u4e00\u76f4\u5728\u6253\u8f6c\uff0c\u8868\u793a\u5b83\u4e00\u76f4\u5728\u5de5\u4f5c\u4e2d\u3002\u6253\u5f00<span lang=\"EN-US\">Dos<\/span>\u4e2d\u7684<span lang=\"EN-US\">netstat<\/span>\u547d\u4ee4\uff0c\u53ef\u4ee5\u770b\u5230\u672c\u5730\u7684<span lang=\"EN-US\">9000<\/span>\u7aef\u53e3\u7684\u72b6\u6001\u4e3a\uff1a<span lang=\"EN-US\">ESTABLISHED<\/span>\uff0c\u8868\u793a\u8be5\u8fdb\u7a0b\u5728\u8054\u673a\u5904\u7406\u4e2d\u3002\u5b9e\u9645\u4e0a\uff0c\u8fd9\u91cc\u6211\u4eec\u5df2\u7ecf\u540c\u65f6\u5411<span lang=\"EN-US\">nginx<\/span>\u53d1\u9001\u4e86\u4e24\u4e2a\u57fa\u4e8e<span lang=\"EN-US\">http<\/span>\u7684<span lang=\"EN-US\">php<\/span>\u8bf7\u6c42\uff0c\u4e00\u4e2a\u662f\u89e3\u6790<span lang=\"EN-US\">index.php<\/span>\uff0c\u800c\u53e6\u4e00\u4e2a\u662f<span lang=\"EN-US\">phpinfo.php<\/span>\uff0c\u8fd9\u6837\u77db\u76fe\u5c31\u51fa\u6765\u4e86\uff0c\u56e0\u4e3a\u6211\u4eec\u7684<span lang=\"EN-US\">windows<\/span>\u7cfb\u7edf\u53ea\u52a0\u8f7d\u4e86\u4e00\u4e2a<span lang=\"EN-US\">http<\/span>\u8fdb\u7a0b\uff0c\u56e0\u6b64\uff0c\u5b83\u65e0\u6cd5\u540c\u65f6\u5904\u7406\u4e24\u4e2a<span lang=\"EN-US\">php<\/span>\u8bf7\u6c42\uff0c\u5b83\u53ea\u80fd\u5148\u5904\u7406\u7b2c\u4e00\u4e2a\u8bf7\u6c42\uff08<span lang=\"EN-US\">index.php<\/span>\uff09\uff0c\u800c<span lang=\"EN-US\">index.php<\/span>\u5374\u53c8\u5728\u7b49\u5f85<span lang=\"EN-US\">phpinfo.php<\/span>\u5904\u7406\u7ed3\u679c\uff0c<span lang=\"EN-US\">phpinfo.php<\/span>\u6ca1\u4eba\u5e2e\u5b83\u5904\u7406\u8bf7\u6c42\uff0c\u56e0\u4e3a\u5b83\u4e00\u76f4\u5728\u7b49\u5f85<span lang=\"EN-US\">index.php<\/span>\u91ca\u653e\u7ed3\u675f\u4fe1\u53f7\uff0c\u56e0\u6b64\uff0c\u9020\u6210\u4e86\u7a0b\u5e8f\u7684\u963b\u585e\u72b6\u6001\uff0c\u9677\u5165\u4e86\u6b7b\u5faa\u73af\u3002\u6240\u4ee5\u6211\u4eec\u5c31\u770b\u5230\u4e86\u6d4f\u89c8\u5668\u7684\u72b6\u6001\u6307\u793a\u4e00\u76f4\u5728\u6253\u8f6c\u3002<span lang=\"EN-US\">Curl()<\/span>\u4e0e<span lang=\"EN-US\">fopen<\/span>\u51fd\u6570\u7684\u539f\u56e0\u4e5f\u76f8\u540c\u3002<\/p>\n<p>\u627e\u5230\u4e86\u539f\u56e0\uff0c\u6211\u4eec\u4e5f\u5c31\u6709\u4e86\u89e3\u51b3\u529e\u6cd5\u3002<\/p>\n<p>\u4e00\u662f\uff0c\u5411\u7cfb\u7edf\u589e\u52a0\u4e00\u4e2ahttp\u8bf7\u6c42\uff0c\u5f53\u4e00\u4e2a<span lang=\"EN-US\">php-cig\u5185\u8981\u52a0\u8f7d\u53e6\u4e00\u4e2a\u8bf7\u6c42\u65f6<\/span>\uff0c\u5b83\u80fd\u591f\u5206\u914d\u5176\u5b83http\u5904\u7406\u989d\u5916\u7684<span lang=\"EN-US\">php<\/span>\u8bf7\u6c42\u3002\u8fd9\u65f6\u9700\u7ed9\u53e6\u4e00\u4e2ahttp sever\u5206\u914d\u4e0d\u540c\u7684\u7aef\u53e3\uff0c\u6bd4\u59828080\u3002nginx\u7684\u6848\u4f8b\u5982\u4e0b\uff1a<\/p>\n<p>http {<br \/>\nserver {<br \/>\nlisten 80;<br \/>\nserver_name 127.0.0.1;<br \/>\nlocation \/ {<br \/>\nindex index.php;<br \/>\nroot \/web\/www\/htdocs;<br \/>\n}<br \/>\n}<br \/>\nserver {<br \/>\nlisten 8080;<br \/>\nserver_name 127.0.0.1;<br \/>\nlocation \/ {<br \/>\nindex index.html;<br \/>\nroot \/web\/www\/htdocs;<br \/>\n}<br \/>\n}<br \/>\ninclude \/opt\/nginx\/conf\/vhosts\/php.conf;<br \/>\n}<\/p>\n<p>\u8fd9\u6837\uff0c\u7aef\u53e3<span lang=\"EN-US\">80<\/span>\u4e0e8<span lang=\"EN-US\">080<\/span>\u53ef\u4ee5\u5206\u522b\u5904\u7406\u4e0d\u540c\u7684\u7a0b\u5e8f\uff0c\u6bd4\u5982\uff1a<\/p>\n<p>test.php<\/p>\n<p>echo file_get_contents(&#8216;http:\/\/localhost:8080\/phpinfo.php&#8217;);<\/p>\n<p><span lang=\"EN-US\">\u00a0\u5f53\u7136\uff0c\u5728*unix\u4e0b\u6709\u66f4\u591a\u9009\u62e9\uff0c\u6bd4\u5982fork\u3002<\/span><\/p>\n<p>\u53e6\u5916\u63d0\u9192\u4e0b\uff0c\u7f51\u4e0a\u6709\u4eba\u8bf4\uff0c\u901a\u8fc7\u53bb\u6389\u5730\u5740\u4e2d\u7684<span lang=\"EN-US\">http:\/\/<\/span>\u534f\u8bae\u6807\u8bb0\uff0c\u800c\u4f7f\u7528\u76f8\u5bf9\u5730\u5740\u5c31\u89c4\u907f\u51fd\u6570\u7684\u68c0\u67e5\uff0c\u5b9e\u9645\u60c5\u51b5\u662f\u4e0d\u662f\u8fd9\u6837\u5462\uff1f\uff01\u5f53\u5728<span lang=\"EN-US\">index.php<\/span>\u4e2d\u4f7f\u7528<span lang=\"EN-US\">file_get_contents(\u2018phpinfo.php\u2019);<\/span>\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u51fd\u6570\u8f93\u51fa\u4e86<span lang=\"EN-US\">phpinfo.php<\/span>\u7684\u6e90\u4ee3\u7801\uff0c\u76f8\u5f53\u4e8e<span lang=\"EN-US\">file_get_contents(\u2018file:\\\\\\c:\\www\\phpinfo.php\u2019);\uff0c\u5b83\u5b9e\u9645\u4e0a\u53ea\u662f\u8bfb\u53d6\u4f60\u7684\u6587\u672c\u5185\u5bb9<\/span>\uff0c\u56e0\u4e3a<span lang=\"EN-US\">file_get_contents()<\/span>\u51fd\u6570\u9996\u5148\u662f\u5904\u7406<span lang=\"EN-US\">file<\/span>\u534f\u8bae\u7684\uff0c\u800c<span lang=\"EN-US\">curl<\/span>\u5219\u76f4\u63a5\u62a5\u9519\u65e0\u6cd5\u89e3\u6790\u3002\u56e0\u6b64\u8fd9\u4e9b\u4eba\u7eaf\u7cb9\u662f\u4e0d\u5b66\u65e0\u672f\u7684\u9a97\u5b50\u3002<\/p>\n<p>\u8fd8\u6709\u4eba\u63d0\u51fa\u4fee\u6539<span lang=\"EN-US\">hosts<\/span>\u6587\u4ef6\uff0c\u589e\u52a0<span lang=\"EN-US\">localhost www.xxx.com<\/span>\u5f71\u5c04\u5173\u7cfb\uff0c\u51fd\u6570\u901a\u8fc7<span lang=\"EN-US\"><a href=\"http:\/\/www.xxx.com\/\" rel=\"nofollow\">www.xxx.com<\/a><\/span>\u8bbf\u95ee\u672c\u5730<span lang=\"EN-US\">php<\/span>\uff0c\u8fd9\u5176\u5b9e\u4e5f\u662f\u4e0d\u6cbb\u672c\u7684\u504f\u65b9\uff0c\u56e0\u4e3a\u8fd9\u53ea\u662f\u65b9\u4fbf\u8ba1\u7b97\u673a\u7684<span lang=\"EN-US\">dns<\/span>\u89e3\u6790\uff0c\u6700\u7ec8<span lang=\"EN-US\"><a href=\"http:\/\/www.xxx.com\/\" rel=\"nofollow\">www.xxx.com<\/a><\/span>\u4ea4\u7ed9<span lang=\"EN-US\">127.0.0.1<\/span>\uff0c\u800c\u540e\u8005\u4ea4\u7ed9\u552f\u4e00http\uff0c\u8fd8\u662f\u963b\u585e\u3002<\/p>\n<p>\u5176\u4ed6\u89e3\u51b3\u65b9\u6cd5:\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/15819351\/can-windows-php-fpm-serve-multiple-simultaneous-requests\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/15819351\/can-windows-php-fpm-serve-multiple-simultaneous-requests<\/a><\/p>\n<p>\u8f6c\u81ea:<\/p>\n<p><a href=\"http:\/\/sumsung753.blog.163.com\/blog\/static\/146364501201341611514461\/\" target=\"_blank\">http:\/\/sumsung753.blog.163.com\/blog\/static\/146364501201341611514461\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e24\u5929\u4e00\u76f4\u5728\u641ewindows\u4e0bnginx+fastcgi\u7684file_get_contents\u8bf7\u6c42\u3002\u6211\u60f3\uff0c\u5f88\u591a\u540c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[92,91,90],"class_list":["post-183","post","type-post","status-publish","format-standard","hentry","category-php","tag-file_get_contents-","tag-file_get_contents","tag-nginx-file_get_contents-","clear"],"_links":{"self":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/comments?post=183"}],"version-history":[{"count":4,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":187,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/183\/revisions\/187"}],"wp:attachment":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/media?parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/categories?post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/tags?post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}