windows环境,nginx服务器,laravel项目,使用guzzlehttp请求自己的接口,配置过了cacert.pem,超时,但是接口确实跑成功了。
php只启动了一个进程,nginx又不维护进程池,一旦出现自己请求自己,就是单线程的递归服务,发请求占用了唯一的线程,一直到超时。
@echo off
REM Windows 下无效
REM set PHP_FCGI_CHILDREN=5
REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
RunHiddenConsole D:\wamp\php-7.2.34-nts-Win32-VC15-x64\php-cgi.exe -b 127.0.0.1:9000 -c D:\wamp\php-7.2.34-nts-Win32-VC15-x64\php.ini
RunHiddenConsole D:\wamp\php-7.2.34-nts-Win32-VC15-x64\php-cgi.exe -b 127.0.0.1:9527-c D:\wamp\php-7.2.34-nts-Win32-VC15-x64\php.ini
RunHiddenConsole D:\wamp\php-7.2.34-nts-Win32-VC15-x64\php-cgi.exe -b 127.0.0.1:9528 -c D:\wamp\php-7.2.34-nts-Win32-VC15-x64\php.ini
echo Starting nginx...
RunHiddenConsole D:\wamp\nginx-1.16.1\nginx-1.16.1\nginx.exe -p D:\wamp\nginx-1.16.1\nginx-1.16.1
首先添加负载均衡:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 1024M;
...
# 这里添加配置 ↓↓↓
upstream php_cgi_pass {
server 127.0.0.1:9000 weight=1;
server 127.0.0.1:9527 weight=1;
server 127.0.0.1:9528 weight=1;
}
...
之后在我们配置的server中替换:
server {
listen 81;
server_name local-ts.com;
......
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
# 这里更改 fastcgi_pass 替换即可 ↓↓↓
fastcgi_pass php_cgi_pass ;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}