您好,登錄后才能下訂單哦!
^_^是在WIN下開發(fā)。配置是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的設(shè)置值(127.0.0.1:9000)。設(shè)置都是以keepalive方式請求,接收到PHP文件時,交于后端過程PHPCGI解析處理(127.0.0.1:9000),等待響應(yīng)。而在本地文件以CURL請求本地環(huán)境中PHP文件時,之前的PHP還在等待CURL后的結(jié)果,這時9000端口已經(jīng)被占用。導(dǎo)致CURL一直在處于等待狀態(tài)。不設(shè)置timeout超時,程序就會卡死。結(jié)果都是false
解決方案:
新開啟一個phpcgi進程設(shè)置不同端口:
例D:\php\php-cgi.exe -b 127.0.0.1:9001 -c D:\phpfind\phpa\php.ini
在需要被CURL的端口或域名設(shè)置中設(shè)置。
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; }
見效果:
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。