{"id":417,"date":"2017-09-29T16:39:07","date_gmt":"2017-09-29T08:39:07","guid":{"rendered":"http:\/\/luchanglong.com.cn\/?p=417"},"modified":"2017-09-29T16:39:07","modified_gmt":"2017-09-29T08:39:07","slug":"%e5%9c%a8%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8a%e5%af%b9-php-fpm-%e5%92%8c-nginx-%e8%bf%9b%e8%a1%8c%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%ae%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/blog.la998.com\/?p=417","title":{"rendered":"\u5728\u670d\u52a1\u5668\u4e0a\u5bf9 PHP-FPM \u548c Nginx \u8fdb\u884c\u5b89\u88c5\u914d\u7f6e\u8be6\u89e3"},"content":{"rendered":"<h3 id=\"toc_0\"><a title=\"View all posts in PHP-FPM\" href=\"https:\/\/laravelacademy.org\/tags\/php-fpm\" target=\"_blank\" rel=\"noopener noreferrer\">PHP-FPM<\/a><\/h3>\n<p><a title=\"View all posts in PHP\" href=\"https:\/\/laravelacademy.org\/tags\/php\" target=\"_blank\" rel=\"noopener noreferrer\">PHP<\/a>-FPM\uff08PHP FastCGI Process Manager\uff09\uff0c\u662f\u7528\u4e8e\u7ba1\u7406 PHP \u8fdb\u7a0b\u6c60\u7684\u8f6f\u4ef6\uff0c\u7528\u4e8e\u63a5\u6536\u548c\u5904\u7406\u6765\u81ea Web\u00a0<a title=\"View all posts in \u670d\u52a1\u5668\" href=\"https:\/\/laravelacademy.org\/tags\/%e6%9c%8d%e5%8a%a1%e5%99%a8\" target=\"_blank\" rel=\"noopener noreferrer\">\u670d\u52a1\u5668<\/a>\uff08\u5982<a title=\"View all posts in Nginx\" href=\"https:\/\/laravelacademy.org\/tags\/nginx\" target=\"_blank\" rel=\"noopener noreferrer\">Nginx<\/a>\uff09\u7684\u8bf7\u6c42\u3002PHP-FPM\u4f1a\u521b\u5efa\u4e00\u4e2a\u4e3b\u8fdb\u7a0b\uff08\u901a\u5e38\u4ee5\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u6839\u7528\u6237\u7684\u8eab\u4efd\u8fd0\u884c\uff09\uff0c\u63a7\u5236\u4f55\u65f6\u4ee5\u53ca\u5982\u4f55\u628a HTTP \u8bf7\u6c42\u8f6c\u53d1\u7ed9\u4e00\u4e2a\u6216\u591a\u4e2a\u5b50\u8fdb\u7a0b\u5904\u7406\u3002PHP-FPM \u4e3b\u8fdb\u7a0b\u8fd8\u63a7\u5236\u7740\u4ec0\u4e48\u65f6\u5019\u521b\u5efa\u548c\u9500\u6bc1 PHP \u5b50\u8fdb\u7a0b\u3002PHP-FPM \u8fdb\u7a0b\u6c60\u4e2d\u7684\u6bcf\u4e2a\u8fdb\u7a0b\u5b58\u5728\u7684\u65f6\u95f4\u90fd\u6bd4\u5355\u4e2a HTTP \u8bf7\u6c42\u957f\uff0c\u53ef\u4ee5\u5904\u740610\u300150\u3001100\u6216\u66f4\u591a\u7684 HTTP \u8bf7\u6c42\u3002<\/p>\n<h4 id=\"toc_1\"><a title=\"View all posts in \u5b89\u88c5\" href=\"https:\/\/laravelacademy.org\/tags\/%e5%ae%89%e8%a3%85\" target=\"_blank\" rel=\"noopener noreferrer\">\u5b89\u88c5<\/a><\/h4>\n<pre><code># <a title=\"View all posts in Ubuntu\" href=\"https:\/\/laravelacademy.org\/tags\/ubuntu\" target=\"_blank\" rel=\"noopener noreferrer\">Ubuntu<\/a>\r\nsudo apt-get install python-software-properties\r\nsudo add-apt-repository ppa:ondrej\/php-5.6\r\nsudo apt-get update\r\nsudo apt-get install php5-fpm php5-cli php5-curl \\\r\n     php5-gd php5-json php5-mcrypt php5-mysqlnd     \r\n<\/code><\/pre>\n<h4 id=\"toc_2\">\u5168\u5c40<a title=\"View all posts in \u914d\u7f6e\" href=\"https:\/\/laravelacademy.org\/tags\/%e9%85%8d%e7%bd%ae\" target=\"_blank\" rel=\"noopener noreferrer\">\u914d\u7f6e<\/a><\/h4>\n<p>\u5728 Ubuntu \u4e2d\uff0cPHP-FPM \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u662f\u00a0<code>\/etc\/php5\/fpm\/php-fpm.conf<\/code>\u3002<\/p>\n<p>\u4e0b\u9762\u662f PHP-FPM \u6700\u91cd\u8981\u7684\u5168\u5c40\u914d\u7f6e\uff0c\u5efa\u8bae\u628a\u9ed8\u8ba4\u503c\u6539\u6210\u4e0b\u9762\u7684\u503c\uff1a<\/p>\n<ul>\n<li><code>emergency_restart_threshold = 10<\/code><br \/>\n\u5728\u6307\u5b9a\u65f6\u95f4\u5185\uff0c\u5982\u679c\u5931\u6548\u7684 PHP-FPM \u5b50\u8fdb\u7a0b\u6570\u8d85\u8fc7\u8fd9\u4e2a\u503c\uff0cPHP-FPM \u4e3b\u8fdb\u7a0b\u5c31\u4f18\u96c5\u91cd\u542f<\/li>\n<li><code>emergency_restart_interval = 1m<\/code><br \/>\n\u8bbe\u5b9a\u00a0<code>emergency_restart_threshold<\/code>\u00a0\u91c7\u7528\u7684\u65f6\u95f4\u8de8\u5ea6<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u914d\u7f6e\u662f PHP-FPM \u8fdb\u7a0b\u7684\u57fa\u672c\u5b89\u5168\u4fdd\u969c\uff0c\u80fd\u89e3\u51b3\u7b80\u5355\u7684\u95ee\u9898\uff0c\u4f46\u662f\u4e0d\u80fd\u89e3\u51b3\u7531\u62d9\u52a3\u7684 PHP \u4ee3\u7801\u5f15\u8d77\u7684\u91cd\u5927\u95ee\u9898\u3002<\/p>\n<blockquote><p>\u6ce8\uff1aPHP-FPM \u7684\u5168\u5c40\u8bbe\u7f6e\u8be6\u7ec6\u4fe1\u606f\u53c2\u89c1<a href=\"http:\/\/php.net\/manual\/zh\/install.fpm.configuration.php\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/php.net\/manual\/zh\/install.fpm.configuration.php<\/a><\/p><\/blockquote>\n<h4 id=\"toc_3\">\u914d\u7f6e\u8fdb\u7a0b\u6c60<\/h4>\n<p>PHP-FPM \u914d\u7f6e\u6587\u4ef6\u7684\u5176\u5b83\u914d\u7f6e\u5185\u5bb9\u662f\u4e00\u4e2a\u540d\u4e3a Pool Definitions \u7684\u533a\u57df\uff0c\u8fd9\u4e2a\u533a\u57df\u91cc\u7684\u914d\u7f6e\u7528\u4e8e\u8bbe\u7f6e\u6bcf\u4e2a PHP-FPM \u8fdb\u7a0b\u6c60\uff0cPHP-FPM \u8fdb\u7a0b\u6c60\u662f\u4e00\u7cfb\u5217\u76f8\u5173\u7684 PHP \u5b50\u8fdb\u7a0b\u3002\u901a\u5e38\uff0c\u4e00\u4e2a PHP \u5e94\u7528\u6709\u81ea\u5df1\u7684\u4e00\u4e2a PHP-FPM \u8fdb\u7a0b\u6c60\u3002<\/p>\n<p>\u5728 Ubuntu \u4e2d\uff0cPool Definitions \u533a\u57df\u53ea\u6709\u4e0b\u9762\u8fd9\u884c\u5185\u5bb9\uff1a<\/p>\n<pre><code>include=\/etc\/php5\/fpm\/pool.d\/*.conf\r\n<\/code><\/pre>\n<p>\u8fd9\u884c\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u8ba9 PHP-FPM \u52a0\u8f7d\u00a0<code>\/etc\/php5\/fpm\/pool.d<\/code>\u00a0\u76ee\u5f55\u4e2d\u7684\u5404\u4e2a\u8fdb\u7a0b\u6c60\u5b9a\u4e49\u6587\u4ef6\u3002\u8fdb\u5165\u8fd9\u4e2a\u76ee\u5f55\uff0c\u5e94\u8be5\u4f1a\u770b\u5230\u4e00\u4e2a\u540d\u4e3a\u00a0<code>www.conf<\/code>\u00a0\u7684\u6587\u4ef6\uff0c\u8fd9\u662f\u540d\u4e3a\u00a0<code>www<\/code>\u00a0\u7684\u9ed8\u8ba4 PHP-FPM \u8fdb\u7a0b\u6c60\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u5404\u4e2a PHP-FPM \u8fdb\u7a0b\u6c60\u90fd\u4ee5\u6307\u5b9a\u7684\u64cd\u4f5c\u7cfb\u7edf\u7528\u6237\u548c\u7528\u6237\u7ec4\u7684\u8eab\u4efd\u8fd0\u884c\u3002\u6211\u4eec\u8981\u914d\u7f6e\u9ed8\u8ba4\u7684\u00a0<code>www<\/code>\u00a0PHP-FPM \u8fdb\u7a0b\u6c60\uff0c\u8ba9\u5b83\u4ee5\u00a0<code>deploy<\/code>\u00a0\u7528\u6237\u548c\u7528\u6237\u7ec4\u7684\u8eab\u4efd\u8fd0\u884c\uff1a<\/p>\n<ul>\n<li><code>user = deploy<\/code><\/li>\n<li><code>group = deploy<\/code><\/li>\n<li><code>listen = 127.0.0.1:9000<\/code>\uff1aPHP-FPM \u8fdb\u7a0b\u6c60\u76d1\u542c\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\uff0c\u8ba9 PHP-FPM \u53ea\u63a5\u53d7 Nginx \u4ece\u8fd9\u91cc\u4f20\u5165\u7684\u8bf7\u6c42\uff0c<code>127.0.0.1:9000<\/code>\u00a0\u8ba9\u6307\u5b9a\u7684 PHP-FPM \u8fdb\u7a0b\u6c60\u76d1\u542c\u672c\u5730\u7aef\u53e3\u00a0<code>9000<\/code>\u00a0\u8fdb\u5165\u7684\u8fde\u63a5\u3002<\/li>\n<li><code>listen.allowed_clients = 127.0.0.1<\/code>\uff1a\u53ef\u4ee5\u5411\u8fd9\u4e2a PHP-FPM \u8fdb\u7a0b\u6c60\u53d1\u9001\u8bf7\u6c42\u7684IP\u5730\u5740\uff08\u4e00\u4e2a\u6216\u591a\u4e2a\uff09\uff0c\u4e3a\u4e86\u5b89\u5168\uff0c\u6211\u628a\u8fd9\u4e2a\u8bbe\u7f6e\u4e3a\u00a0<code>127.0.0.1<\/code>\uff0c\u5373\u53ea\u6709\u5f53\u524d\u8bbe\u5907\u80fd\u628a\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u8fd9\u4e2a PHP-FPM \u8fdb\u7a0b\u6c60\u3002<\/li>\n<li><code>pm.max_children = 15<\/code>\uff1a\u8fd9\u4e2a\u8bbe\u7f6e\u8bbe\u5b9a\u4efb\u4f55\u65f6\u95f4\u70b9 PHP-FPM \u8fdb\u7a0b\u6c60\u4e2d\u6700\u591a\u80fd\u6709\u591a\u5c11\u4e2a\u8fdb\u7a0b\u3002\u8fd9\u4e2a\u8bbe\u7f6e\u6ca1\u6709\u7edd\u5bf9\u6b63\u786e\u7684\u503c\uff0c\u4f60\u5e94\u8be5\u6d4b\u8bd5\u4f60\u7684 PHP \u5e94\u7528\uff0c\u786e\u5b9a\u6bcf\u4e2a PHP \u8fdb\u7a0b\u9700\u8981\u4f7f\u7528\u591a\u5c11\u5185\u5b58\uff0c\u7136\u540e\u628a\u8fd9\u4e2a\u8bbe\u7f6e\u8bbe\u5b9a\u4e3a\u53ef\u7528\u5185\u5b58\u80fd\u5bb9\u7eb3\u7684 PHP \u8fdb\u7a0b\u603b\u6570\u3002<\/li>\n<li><code>pm.start_servers = 3<\/code>\uff1aPHP-FPM \u542f\u52a8\u65f6 PHP-FPM \u8fdb\u7a0b\u6c60\u7acb\u5373\u53ef\u7528\u7684\u8fdb\u7a0b\u6570\u3002<\/li>\n<li><code>pm.min_spare_servers = 2<\/code>\uff1aPHP \u5e94\u7528\u7a7a\u95f2\u65f6 PHP-FPM \u8fdb\u7a0b\u6c60\u4e2d\u53ef\u4ee5\u5b58\u5728\u7684\u8fdb\u7a0b\u6570\u91cf\u6700\u5c0f\u503c\u3002\u8fd9\u4e2a\u8bbe\u7f6e\u7684\u503c\u4e00\u822c\u548c\u00a0<code>pm.start_servers<\/code>\u00a0\u4e00\u6837\u3002<\/li>\n<li><code>pm.max_spare_servers = 4<\/code>\uff1aPHP \u5e94\u7528\u7a7a\u95f2\u65f6 PHP-FPM \u8fdb\u7a0b\u6c60\u4e2d\u53ef\u4ee5\u5b58\u5728\u7684\u8fdb\u7a0b\u6570\u91cf\u6700\u5927\u503c\u3002<\/li>\n<li><code>pm.max_requests = 1000<\/code>\uff1a\u56de\u6536\u8fdb\u7a0b\u4e4b\u524d\uff0cPHP-FPM \u8fdb\u7a0b\u6c60\u4e2d\u5404\u4e2a\u8fdb\u7a0b\u6700\u591a\u80fd\u5904\u7406\u7684 HTTP \u8bf7\u6c42\u6570\u91cf\u3002\u8fd9\u4e2a\u8bbe\u7f6e\u6709\u52a9\u4e8e\u907f\u514d PHP \u6269\u5c55\u6216\u5e93\u56e0\u4e3a\u7f16\u5199\u62d9\u52a3\u800c\u5bfc\u81f4\u5185\u5b58\u4e0d\u65ad\u6cc4\u9732\u3002<\/li>\n<li><code>slowlog = \/path\/to\/slowlog.log<\/code>\uff1a\u8fd9\u4e2a\u8bbe\u7f6e\u7684\u503c\u662f\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u7edd\u5bf9\u8def\u5f84\u3002\u8fd9\u4e2a\u65e5\u5fd7\u6587\u4ef6\u7528\u4e8e\u8bb0\u5f55\u5904\u7406\u65f6\u95f4\u8d85\u8fc7\u00a0<code>n<\/code>\u00a0\u79d2\u7684 HTTP \u8bf7\u6c42\u4fe1\u606f\uff0c\u4ee5\u4fbf\u627e\u51fa PHP \u5e94\u7528\u7684\u74f6\u9888\uff0c\u8fdb\u800c\u8fdb\u884c\u8c03\u8bd5\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cPHP-FPM \u8fdb\u7a0b\u6c60\u6240\u5c5e\u7684\u7528\u6237\u548c\u7528\u6237\u7ec4\u8981\u5bf9\u8fd9\u4e2a\u65e5\u5fd7\u6587\u4ef6\u6709\u5199\u6743\u9650\u3002<\/li>\n<li><code>request_slowlog_timeout = 5s<\/code>\uff1a\u5982\u679c\u5f53\u524d HTTP \u8bf7\u6c42\u7684\u5904\u7406\u65f6\u95f4\u8d85\u8fc7\u6307\u5b9a\u7684\u503c\uff0c\u5c31\u628a\u8bf7\u6c42\u7684\u56de\u6eaf\u4fe1\u606f\u5199\u5165\u00a0<code>slowlog<\/code>\u00a0\u8bbe\u7f6e\u6307\u5b9a\u7684\u65e5\u5fd7\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u7f16\u8f91\u4e4b\u540e\u4fdd\u5b58\u6587\u4ef6\uff0c\u7136\u540e\u91cd\u542f PHP-FPM \u4e3b\u8fdb\u7a0b\uff1a<\/p>\n<pre><code>sudo service php5-fpm restart\r\n<\/code><\/pre>\n<blockquote><p>\u6ce8\uff1a\u66f4\u591a\u914d\u7f6e\u4fe1\u606f\u53c2\u89c1<a href=\"http:\/\/php.net\/manual\/zh\/install.fpm.configuration.php\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/php.net\/manual\/zh\/install.fpm.configuration.php<\/a><\/p><\/blockquote>\n<h3 id=\"toc_4\">Nginx<\/h3>\n<p>Nginx \u662f Web \u670d\u52a1\u5668\uff0c\u7c7b\u4f3c Apache\uff0c\u4e0d\u8fc7\u66f4\u5bb9\u6613\u914d\u7f6e\uff0c\u800c\u4e14\u8fd0\u884c\u65f6\u5360\u7528\u5185\u5b58\u66f4\u5c11\u3002\u8fd9\u91cc\u6211\u4eec\u4e0d\u6df1\u5165\u63a2\u8ba8 Nginx\uff0c\u53ea\u662f\u544a\u8bc9\u4f60\u5982\u4f55\u5b89\u88c5\uff0c\u4ee5\u53ca\u5982\u4f55\u628a\u76f8\u5e94\u7684\u8bf7\u6c42\u8f6c\u53d1\u7ed9 PHP-FPM \u8fdb\u7a0b\u6c60\u3002<\/p>\n<h4 id=\"toc_5\">\u5b89\u88c5<\/h4>\n<pre><code># Ubuntu\r\nsudo add-apt-repository ppa:nginx\/stable\r\nsudo apt-get update\r\nsudo apt-get install nginx\r\n\r\n# CentOS\r\nsudo yum install nginx\r\nsudo systemctl enable nginx.service\r\nsudo systemctl start nginx.service\r\n<\/code><\/pre>\n<h4 id=\"toc_6\">\u865a\u62df\u4e3b\u673a<\/h4>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4e3a PHP \u5e94\u7528\u914d\u7f6e\u4e00\u4e2a\u865a\u62df\u4e3b\u673a\u3002\u865a\u62df\u4e3b\u673a\u662f\u4e00\u7cfb\u5217\u8bbe\u7f6e\uff0c\u7528\u4e8e\u544a\u77e5 Nginx PHP \u5e94\u7528\u7684\u57df\u540d\u3001\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u4f4d\u7f6e\uff0c\u5df2\u7ecf\u5982\u4f55\u628a HTTP \u8bf7\u6c42\u8f6c\u53d1\u7ed9 PHP-FPM \u8fdb\u7a0b\u6c60\uff1a<\/p>\n<pre><code>server {\r\n    listen 80;\r\n    server_name example.com;\r\n    index index.php\r\n    client_max_body_size 50M;\r\n    error_log \/home\/deploy\/apps\/logs\/example.error.log;\r\n    access_log \/home\/deploy\/apps\/logs\/example.access.log;\r\n    root \/home\/deploy\/apps\/example.com\/current\/public;\r\n\r\n    location \/ {\r\n        try_files $uri $uri\/ \/index.php$is_args$args;\r\n    }\r\n\r\n    location ~ \\.php {\r\n        try_files $uri = 404;\r\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\r\n        include fastcgi_params;\r\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n        fastcgi_param SCRIPT_NAME $fastcgi_script_name;\r\n        fastcgi_index index.php;\r\n        fastcgi_pass 127.0.0.1:9000;\r\n    }\r\n} \r\n<\/code><\/pre>\n<p>\u4e0b\u9762\u7b80\u8981\u8bf4\u660e\u4e0b\u6bcf\u4e2a\u865a\u62df\u4e3b\u673a\u8bbe\u7f6e\uff1a<\/p>\n<ul>\n<li><code>listen<\/code>\uff1a\u8bbe\u7f6e Nginx \u76d1\u542c\u54ea\u4e2a\u7aef\u53e3\u8fdb\u5165\u7684 HTTP \u8bf7\u6c42\u3002\u4e00\u822c HTTP \u8bf7\u6c42\u4ece\u00a0<code>80<\/code>\u00a0\u7aef\u53e3\u8fdb\u5165\uff0cHTTPS \u8bf7\u6c42\u4ece\u00a0<code>443<\/code>\u7aef\u53e3\u8fdb\u5165\u3002<\/li>\n<li><code>server_name<\/code>\uff1a\u7528\u4e8e\u8bc6\u522b\u865a\u62df\u4e3b\u673a\u7684\u57df\u540d\uff0c\u8fd9\u4e2a\u8981\u8bbe\u7f6e\u4e3a\u4f60\u7684\u5e94\u7528\u4f7f\u7528\u7684\u57df\u540d\uff0c\u800c\u4e14\u57df\u540d\u8981\u6307\u5411\u670d\u52a1\u5668\u7684 IP \u5730\u5740\u3002\u5982\u679c HTTP \u8bf7\u6c42\u5934\u4e2d\u00a0<code>Host<\/code>\u00a0\u9996\u90e8\u7684\u503c\u548c\u865a\u62df\u4e3b\u673a\u4e2d\u00a0<code>server_name<\/code>\u00a0\u7684\u503c\u76f8\u5339\u914d\uff0cNginx \u5c31\u4f1a\u628a\u8fd9\u4e2a HTTP \u8bf7\u6c42\u53d1\u9001\u7ed9\u8fd9\u4e2a\u865a\u62df\u4e3b\u673a\u3002<\/li>\n<li><code>index<\/code>\uff1aHTTP \u8bf7\u6c42 URI \u6ca1\u6709\u6307\u5b9a\u6587\u4ef6\u65f6\u7684\u9ed8\u8ba4\u6587\u4ef6\u3002<\/li>\n<li><code>client_max_body_size<\/code>\uff1a\u5bf9\u8fd9\u4e2a\u865a\u62df\u4e3b\u673a\u6765\u8bf4\uff0cNginx \u63a5\u53d7 HTTP \u8bf7\u6c42\u4e3b\u4f53\u957f\u5ea6\u7684\u6700\u5927\u503c\u3002\u5982\u679c\u8bf7\u6c42\u4e3b\u4f53\u957f\u5ea6\u8d85\u8fc7\u8fd9\u4e2a\u503c\uff0cNginx \u4f1a\u8fd4\u56de 4XX \u54cd\u5e94\u3002<\/li>\n<li><code>error_log<\/code>\uff1a\u8fd9\u4e2a\u865a\u62df\u4e3b\u673a\u9519\u8bef\u65e5\u5fd7\u6587\u4ef6\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u8def\u5f84\u3002<\/li>\n<li><code>access_log<\/code>\uff1a\u8fd9\u4e2a\u865a\u62df\u4e3b\u673a\u8bbf\u95ee\u65e5\u5fd7\u6587\u4ef6\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u8def\u5f84\u3002<\/li>\n<li><code>root<\/code>\uff1a\u5e94\u7528\u6839\u76ee\u5f55\u8def\u5f84\u3002<\/li>\n<\/ul>\n<p>\u9664\u4e86\u4e0a\u8ff0\u8bbe\u7f6e\u5916\uff0c\u8fd8\u6709\u4e24\u4e2a\u00a0<code>location<\/code>\u00a0\u5757\uff0c\u8fd9\u4e24\u4e2a\u00a0<code>location<\/code>\u00a0\u5757\u7684\u4f5c\u7528\u662f\u544a\u8bc9 Nginx \u5982\u4f55\u5904\u7406\u5339\u914d\u6307\u5b9a URL \u6a21\u5f0f\u7684 HTTP \u8bf7\u6c42\uff1a<\/p>\n<p><code>location \/ {}<\/code>\u00a0\u4f7f\u7528 try_files \u6307\u4ee4\u67e5\u627e\u5339\u914d\u6240\u8bf7\u6c42 URI \u7684\u6587\u4ef6\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230\uff0c\u518d\u67e5\u627e\u5339\u914d\u6240\u8bf7\u6c42 URI \u7684\u76ee\u5f55\uff0c\u5982\u679c\u76ee\u5f55\u4e5f\u6ca1\u6709\u627e\u5230\uff0c\u5219\u628a HTTP \u8bf7\u6c42\u7684 URI \u91cd\u5199\u4e3a\u00a0<code>\/index.php<\/code>\uff0c\u5982\u679c\u6709\u67e5\u8be2\u5b57\u7b26\u4e32\u7684\u8bdd\uff0c\u8fd8\u4f1a\u628a\u67e5\u8be2\u5b57\u7b26\u4e32\u9644\u52a0\u5230 URI \u7684\u672b\u5c3e\uff0c\u8fd9\u4e2a\u91cd\u5199\u7684 URL\uff0c\u4ee5\u53ca\u6240\u6709\u4ee5\u00a0<code>.php<\/code>\u00a0\u7ed3\u5c3e\u7684URI\uff0c\u90fd\u7531\u00a0<code>location ~ \\.php {}<\/code>\u00a0\u5757\u7ba1\u7406\u3002<\/p>\n<p><code>location ~ \\.php {}<\/code>\u00a0\u5757\u628a HTTP \u8bf7\u6c42\u8f6c\u53d1\u7ed9 PHP-FPM \u8fdb\u7a0b\u6c60\u8fdb\u884c\u5904\u7406\uff0c\u5728\u8fd9\u4e2a\u5757\u4e2d\u6211\u4eec\u628a PHP \u8bf7\u6c42\u8f6c\u53d1\u5230\u7aef\u53e3\u00a0<code>9000<\/code>\u00a0\u8ba9 PHP-FPM \u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<blockquote><p>\u6ce8\uff1a<code>location ~ \\.php {}<\/code>\u00a0\u5176\u5b83\u51e0\u884c\u7684\u4f5c\u7528\u662f\u907f\u514d\u6f5c\u5728\u7684\u8fdc\u7a0b\u4ee3\u7801\u6267\u884c\u653b\u51fb\uff1a<a href=\"https:\/\/nealpoole.com\/blog\/2011\/04\/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/nealpoole.com\/blog\/2011\/04\/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration\/<\/a><\/p><\/blockquote>\n<p>\u5728 Ubuntu \u4e2d\u6211\u4eec\u5fc5\u987b\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5728\u00a0<code>\/etc\/nginx\/sites-enable<\/code>\u00a0\u76ee\u5f55\u4e0b\u521b\u5efa\u865a\u62df\u4e3b\u673a\u914d\u7f6e\u6587\u4ef6\u7684\u7b26\u53f7\u94fe\u63a5\uff1a<\/p>\n<pre><code>sudo ln -s \/etc\/nginx\/sites-available\/example.conf \/etc\/nginx\/sites-enabled\/example.conf;\r\n<\/code><\/pre>\n<p>\u6700\u540e\uff0c\u6267\u884c\u4e0b\u8ff0\u547d\u4ee4\uff0c\u91cd\u542f Nginx\uff1a<\/p>\n<pre><code># Ubuntu\r\nsudo service nginx restart\r\n\r\n# CentOS\r\nsudo systemctl restart nginx.service\r\n<\/code><\/pre>\n<p>\u73b0\u5728\u670d\u52a1\u5668\u53ef\u4ee5\u8fd0\u884c PHP \u5e94\u7528\u4e86\u3002Nginx \u914d\u7f6e\u6709\u5f88\u591a\u79cd\uff0c\u8fd9\u91cc\u53ea\u662f\u6700\u57fa\u672c\u7684\u914d\u7f6e\uff0c\u66f4\u591a\u914d\u7f6e\u4fe1\u606f\uff0c\u8bf7\u53c2\u8003\u4ee5\u4e0b\u8d44\u6e90\uff1a<\/p>\n<ul>\n<li><a href=\"http:\/\/nginx.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/nginx.org<\/a><\/li>\n<li><a href=\"http:\/\/www.nginx.cn\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.nginx.cn<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/h5bp\/server-configs-nginx\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/h5bp\/server-configs-nginx<\/a><\/li>\n<\/ul>\n<h3 id=\"toc_7\">\u81ea\u52a8\u914d\u7f6e\u670d\u52a1\u5668<\/h3>\n<p>\u914d\u7f6e\u670d\u52a1\u5668\u662f\u4e2a\u5f88\u6f2b\u957f\u7684\u8fc7\u7a0b\uff0c\u800c\u4e14\u5f88\u67af\u71e5\uff0c\u5982\u679c\u624b\u52a8\u914d\u7f6e\u5f88\u591a\u670d\u52a1\u5668\uff0c\u8fd9\u79cd\u611f\u89c9\u4f1a\u66f4\u5f3a\u70c8\u3002\u5e78\u597d\uff0c\u6709\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u6211\u4eec\u81ea\u52a8\u914d\u7f6e\u670d\u52a1\u5668\uff0c\u4e0b\u9762\u662f\u51e0\u4e2a\u6d41\u884c\u7684\u670d\u52a1\u5668\u914d\u7f6e\u5de5\u5177\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/puppet.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Puppet<\/a><\/li>\n<li><a href=\"https:\/\/www.chef.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Chef<\/a><\/li>\n<li><a href=\"https:\/\/www.ansible.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Ansible<\/a><\/li>\n<li><a href=\"https:\/\/saltstack.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">SaltStack<\/a><\/li>\n<\/ul>\n<p>\u5404\u4e2a\u5de5\u5177\u4e4b\u95f4\u6709\u6240\u5dee\u522b\uff0c\u4f46\u662f\u76ee\u6807\u662f\u4e00\u81f4\u7684 \u2014\u2014 \u6839\u636e\u7cbe\u786e\u7684\u89c4\u5219\u81ea\u52a8\u914d\u7f6e\u65b0\u670d\u52a1\u5668\u3002\u5982\u679c\u8981\u7ba1\u7406\u591a\u53f0\u670d\u52a1\u5668\uff0c\u6211\u5f3a\u70c8\u5efa\u8bae\u7814\u7a76\u4f7f\u7528\u914d\u7f6e\u5de5\u5177\uff0c\u8fd9\u6837\u53ef\u4ee5\u8282\u7701\u5927\u91cf\u65f6\u95f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP-FPM PHP-FPM\uff08PHP FastCGI Process Manager\uff09\uff0c\u662f\u7528\u4e8e\u7ba1\u7406 PHP  &hellip; <a href=\"https:\/\/blog.la998.com\/?p=417\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u5728\u670d\u52a1\u5668\u4e0a\u5bf9 PHP-FPM \u548c Nginx \u8fdb\u884c\u5b89\u88c5\u914d\u7f6e\u8be6\u89e3<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-417","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=417"}],"version-history":[{"count":1,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions"}],"predecessor-version":[{"id":418,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions\/418"}],"wp:attachment":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}