您好,登錄后才能下訂單哦!
^_^是在WIN下開發。配置是nignxphp mysql
默認時啟動phpcgi是
D:\php \php-cgi.exe-b 127.0.0.1:9000 -c D:\phpfind\phpa\php.ini
先看NGINX配置
location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }
NGINX中,看PHP文件塊fastcig-pass的設置值(127.0.0.1:9000)。設置都是以keepalive方式請求,接收到PHP文件時,交于后端過程PHPCGI解析處理(127.0.0.1:9000),等待響應。而在本地文件以CURL請求本地環境中PHP文件時,之前的PHP還在等待CURL后的結果,這時9000端口已經被占用。導致CURL一直在處于等待狀態。不設置timeout超時,程序就會卡死。結果都是false
解決方案:
新開啟一個phpcgi進程設置不同端口:
例D:\php\php-cgi.exe -b 127.0.0.1:9001 -c D:\phpfind\phpa\php.ini
在需要被CURL的端口或域名設置中設置。
location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }
這樣就可以請求了。但是不能請求同一個域下的文件。
這樣可以在nginx中使用php-cgi負載均衡:
upstream backend{ server 127.0.0.1:9000; server 127.0.0.1:9001; } location ~ \.php(.*)$ { fastcgi_pass backend; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }
見效果:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。