{"id":476,"date":"2021-05-12T05:29:41","date_gmt":"2021-05-12T05:29:41","guid":{"rendered":"http:\/\/robinluo.top\/?p=476"},"modified":"2023-03-13T16:05:34","modified_gmt":"2023-03-13T16:05:34","slug":"php-nginx-%e7%8e%af%e5%a2%83%e4%b8%8b%e8%bd%bd","status":"publish","type":"post","link":"https:\/\/robinluo.top\/?p=476","title":{"rendered":"php nginx \u73af\u5883\u4e0b\u8f7d"},"content":{"rendered":"\n<p>nginx \u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root \/var\/www\/php;  \/\/ \u65b0\u7248\u672c root \u8981\u653e\u5728\u8fd9\u91cc\u6b21\u554a\u80fd\u8d77\u4f5c\u7528\nlocation   ~\\.php$ {\n                        root            \/var\/www\/php;\n                        index          index.php index.htmlindex.htm;\n                        fastcgi_pass    unix:\/run\/php\/php7.4-fpm.sock;\n                        fastcgi_index   index.php;\n                        include         fastcgi_params;\n                }<\/code><\/pre>\n\n\n\n<p>\u670d\u52a1\u5668 \u5b89\u88c5 php-fpm<\/p>\n\n\n\n<p>\u7136\u540e nginx \u901a\u8fc7unix:\/run\/php\/php7.4-fpm.sock \u8f6c\u53d1\u8bf7\u6c42\u5230php-fpm\u4e0a<\/p>\n\n\n\n<p>tips : fastcgi_params \u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff08\u82e5\u8bbf\u95ee\u9996\u9875\u7a7a\u767d\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fastcgi_param SCRIPT_FILENAME     $document_root$fastcgi_script_name;\nfastcgi_param PATH_INFO           $fastcgi_script_name;\n\/\/\u4ecenginx\u53d8\u91cf \u4f20\u5230  cgi\u53d8\u91cf\uff08\u5373php\u53d8\u91cf\uff09<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>fastcgi_param \u53c2\u6570\u8be6\u89e3  \u5c31\u662f\u4ecenginx\u4f20\u8fc7\u53bb\u7684\u53d8\u91cf \u53ef\u4ee5\u901a\u8fc7_SERVER \u83b7\u53d6<\/p>\n\n\n\n<p>\u5173\u952e\u53d8\u91cf\u662f <\/p>\n\n\n\n<p>DOCUMENT_ROOT  php \u9879\u76ee\u6587\u4ef6\u6240\u5728\u6587\u4ef6\u5939<\/p>\n\n\n\n<p>SCRIPT_NAME  php \u9879\u76ee\u6587\u4ef6<\/p>\n\n\n\n<p>SCRIPT_FILENAME  $document_root$fastcgi_script_name; \/\/php \u6587\u4ef6\u5168\u8def\u5f84<\/p>\n\n\n\n<p>nginx\u53d8\u91cf \u90fd\u662f$\u5f00\u5934\u5c0f\u5199\u4e0b\u5212\u7ebf\u7ec4\u5408<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\nfastcgi_param  QUERY_STRING       $query_string;\r\nfastcgi_param  REQUEST_METHOD     $request_method;\r\nfastcgi_param  CONTENT_TYPE       $content_type;\r\nfastcgi_param  CONTENT_LENGTH     $content_length;\r\n\r\nfastcgi_param  SCRIPT_NAME        $fastcgi_script_name;\r\nfastcgi_param  REQUEST_URI        $request_uri;\r\nfastcgi_param  DOCUMENT_URI       $document_uri;\r\nfastcgi_param  DOCUMENT_ROOT      $document_root;\r\nfastcgi_param  SERVER_PROTOCOL    $server_protocol;\r\nfastcgi_param  REQUEST_SCHEME     $scheme;\r\nfastcgi_param  HTTPS              $https if_not_empty;\r\n\r\nfastcgi_param  GATEWAY_INTERFACE  CGI\/1.1;\r\nfastcgi_param  SERVER_SOFTWARE    nginx\/$nginx_version;\r\n\r\nfastcgi_param  REMOTE_ADDR        $remote_addr;\r\nfastcgi_param  REMOTE_PORT        $remote_port;\r\nfastcgi_param  SERVER_ADDR        $server_addr;\r\nfastcgi_param  SERVER_PORT        $server_port;\r\nfastcgi_param  SERVER_NAME        $server_name;\r\n\r\n# PHP only, required if PHP was built with --enable-force-cgi-redirect\r\nfastcgi_param  REDIRECT_STATUS    200;<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u53c2\u6570\u53ef\u4ee5\u901a\u8fc7 php  $_SERVER[&#8216;SERVER_NAME&#8217;]  \u83b7\u53d6\u53d8\u91cf\u503c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>nginx \u914d\u7f6e \u670d\u52a1\u5668 \u5b89\u88c5 php-fpm \u7136\u540e nginx \u901a\u8fc7unix:\/run\/php\/php7.4-fpm.sock \u8f6c\u53d1\u8bf7\u6c42\u5230php-fpm\u4e0a tips : fastcgi_params \u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff08\u82e5\u8bbf\u95ee\u9996\u9875\u7a7a\u767d\uff09 fastcgi_param \u53c2\u6570\u8be6\u89e3 \u5c31\u662f\u4ecenginx\u4f20\u8fc7\u53bb\u7684\u53d8\u91cf \u53ef\u4ee5\u901a\u8fc7_SERVER \u83b7\u53d6 \u5173\u952e\u53d8\u91cf\u662f DOCUMENT_ROOT php \u9879\u76ee\u6587\u4ef6\u6240\u5728\u6587\u4ef6\u5939 SCRIPT_NAME php \u9879\u76ee\u6587\u4ef6 SCRIPT_FILENAME $document_root$fastcgi_script_name; \/\/php \u6587\u4ef6\u5168\u8def\u5f84 nginx\u53d8\u91cf \u90fd\u662f$\u5f00\u5934\u5c0f\u5199\u4e0b\u5212\u7ebf\u7ec4\u5408 \u4ee5\u4e0a\u53c2\u6570\u53ef\u4ee5\u901a\u8fc7 php $_SERVER[&#8216;SERVER_NAME&#8217;] \u83b7\u53d6\u53d8\u91cf\u503c<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[126,124],"_links":{"self":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/476"}],"collection":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=476"}],"version-history":[{"count":7,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions"}],"predecessor-version":[{"id":767,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions\/767"}],"wp:attachment":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}