Nginx + php-fpm 在 Windows 10、CentOS 8 下的串行、并行支持与否的分析测试与解决
1、Nginx + php-fpm 在 Windows 10 下的情况表现,当在一个请求(http://api.channel-pub-api.localhost)中 CURL 另一个请求(http://api.channel-pub-api.localhost)时,报错:fopen(http://api.channel-pub-api.localhost/qq/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac63): failed to open stream: HTTP request failed! 。如图1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | { "name": "HTTP Client Exception", "message": "fopen(http://api.channel-pub-api.localhost/qq/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac63): failed to open stream: HTTP request failed! ", "code": 2, "type": "yii\\httpclient\\Exception", "file": "E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2-httpclient\\src\\StreamTransport.php", "line": 68, "stack-trace": [ "#0 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2-httpclient\\src\\Transport.php(41): yii\\httpclient\\StreamTransport->send(Object(yii\\httpclient\\Request))", "#1 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2-httpclient\\src\\Client.php(259): yii\\httpclient\\Transport->batchSend(Array)", "#2 E:\\wwwroot\\channel-pub-api-feature-task-group\\common\\logics\\http\\channel_pub_api\\Article.php(55): yii\\httpclient\\Client->batchSend(Array)", "#3 E:\\wwwroot\\channel-pub-api-feature-task-group\\common\\services\\TaskGroupService.php(117): common\\logics\\http\\channel_pub_api\\Article->batchPostArticlesStandard('015ce30b116ce86...', Array)", "#4 E:\\wwwroot\\channel-pub-api-feature-task-group\\api\\filters\\TaskGroupFilter.php(45): common\\services\\TaskGroupService::createMultipleSync(Array)", "#5 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\ActionFilter.php(92): api\\filters\\TaskGroupFilter->afterAction(Object(api\\rests\\task_group\\CreateAction), Array)", "#6 [internal function]: yii\\base\\ActionFilter->afterFilter(Object(yii\\base\\ActionEvent))", "#7 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Component.php(627): call_user_func(Array, Object(yii\\base\\ActionEvent))", "#8 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Controller.php(305): yii\\base\\Component->trigger('afterAction', Object(yii\\base\\ActionEvent))", "#9 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\rest\\Controller.php(76): yii\\base\\Controller->afterAction(Object(api\\rests\\task_group\\CreateAction), Array)", "#10 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Controller.php(159): yii\\rest\\Controller->afterAction(Object(api\\rests\\task_group\\CreateAction), Array)", "#11 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Module.php(528): yii\\base\\Controller->runAction('create', Array)", "#12 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\web\\Application.php(103): yii\\base\\Module->runAction('v1/task-group/c...', Array)", "#13 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Application.php(386): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))", "#14 E:\\wwwroot\\channel-pub-api-feature-task-group\\api\\web\\index.php(17): yii\\base\\Application->run()", "#15 {main}" ], "previous": { "name": "PHP Warning", "message": "fopen(http://api.channel-pub-api.localhost/qq/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac63): failed to open stream: HTTP request failed! ", "code": 2, "type": "yii\\base\\ErrorException", "file": "E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2-httpclient\\src\\StreamTransport.php", "line": 61, "stack-trace": [ "#0 [internal function]: yii\\base\\ErrorHandler->handleError(2, 'fopen(http://ap...', 'E:\\\\wwwroot\\\\chan...', 61, Array)", "#1 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2-httpclient\\src\\StreamTransport.php(61): fopen('http://api.chan...', 'rb', false, Resource id #205)", "#2 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2-httpclient\\src\\Transport.php(41): yii\\httpclient\\StreamTransport->send(Object(yii\\httpclient\\Request))", "#3 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2-httpclient\\src\\Client.php(259): yii\\httpclient\\Transport->batchSend(Array)", "#4 E:\\wwwroot\\channel-pub-api-feature-task-group\\common\\logics\\http\\channel_pub_api\\Article.php(55): yii\\httpclient\\Client->batchSend(Array)", "#5 E:\\wwwroot\\channel-pub-api-feature-task-group\\common\\services\\TaskGroupService.php(117): common\\logics\\http\\channel_pub_api\\Article->batchPostArticlesStandard('015ce30b116ce86...', Array)", "#6 E:\\wwwroot\\channel-pub-api-feature-task-group\\api\\filters\\TaskGroupFilter.php(45): common\\services\\TaskGroupService::createMultipleSync(Array)", "#7 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\ActionFilter.php(92): api\\filters\\TaskGroupFilter->afterAction(Object(api\\rests\\task_group\\CreateAction), Array)", "#8 [internal function]: yii\\base\\ActionFilter->afterFilter(Object(yii\\base\\ActionEvent))", "#9 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Component.php(627): call_user_func(Array, Object(yii\\base\\ActionEvent))", "#10 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Controller.php(305): yii\\base\\Component->trigger('afterAction', Object(yii\\base\\ActionEvent))", "#11 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\rest\\Controller.php(76): yii\\base\\Controller->afterAction(Object(api\\rests\\task_group\\CreateAction), Array)", "#12 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Controller.php(159): yii\\rest\\Controller->afterAction(Object(api\\rests\\task_group\\CreateAction), Array)", "#13 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Module.php(528): yii\\base\\Controller->runAction('create', Array)", "#14 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\web\\Application.php(103): yii\\base\\Module->runAction('v1/task-group/c...', Array)", "#15 E:\\wwwroot\\channel-pub-api-feature-task-group\\vendor\\yiisoft\\yii2\\base\\Application.php(386): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))", "#16 E:\\wwwroot\\channel-pub-api-feature-task-group\\api\\web\\index.php(17): yii\\base\\Application->run()", "#17 {main}" ] } } |
2、编辑 Nginx 配置文件,复制 server:API 为 server:LOCALHOST API。调整 listen 81、server_name localhost、fastcgi_pass 127.0.0.1:9001。总计 3 项配置值。如图2、图3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | ## FRONTEND ## server { charset utf-8; client_max_body_size 200m; client_body_buffer_size 1024k; fastcgi_read_timeout 180s; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name www.channel-pub-api.localhost www.channel-pub-api-localhost.chinamcloud.cn auth.channel-pub.wjdev.chinamcloud.cn; root E:/wwwroot/channel-pub-api-feature-task-group/frontend/web; index index.php; access_log logs/www.channel-pub-api.localhost.access.log; error_log logs/www.channel-pub-api.localhost.error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } } ## API ## server { charset utf-8; client_max_body_size 200m; client_body_buffer_size 1024k; fastcgi_read_timeout 180s; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name api.channel-pub-api.localhost api.channel-pub-api-localhost.chinamcloud.cn; root E:/wwwroot/channel-pub-api-feature-task-group; index index.php; access_log logs/api.channel-pub-api.localhost.access.log; error_log logs/api.channel-pub-api.localhost.error.log; location / { root E:/wwwroot/channel-pub-api-feature-task-group/api/web; try_files $uri $uri/ /api/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/assets/.+\.php(/|$) { deny all; } } location /baijia { alias E:/wwwroot/channel-pub-api-feature-task-group/baijia/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /baijia/ { # return 301 /baijia; #} # prevent the directory redirect to the URL with a trailing slash location = /baijia { # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /baijia/baijia/web/index.php$is_args$args; } # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /baijia/baijia/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/baijia/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/baijia/assets/.+\.php(/|$) { deny all; } } location /customize { alias E:/wwwroot/channel-pub-api-feature-task-group/customize/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /customize/ { # return 301 /customize; #} # prevent the directory redirect to the URL with a trailing slash location = /customize { # if your location is "/customize", try use "/customize/customize/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /customize/customize/web/index.php$is_args$args; } # if your location is "/customize", try use "/customize/customize/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /customize/customize/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/customize/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/customize/assets/.+\.php(/|$) { deny all; } } location /netease { alias E:/wwwroot/channel-pub-api-feature-task-group/netease/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /netease/ { # return 301 /netease; #} # prevent the directory redirect to the URL with a trailing slash location = /netease { # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /netease/netease/web/index.php$is_args$args; } # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /netease/netease/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/netease/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/netease/assets/.+\.php(/|$) { deny all; } } location /qq { alias E:/wwwroot/channel-pub-api-feature-task-group/qq/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /qq/ { # return 301 /qq; #} # prevent the directory redirect to the URL with a trailing slash location = /qq { # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /qq/qq/web/index.php$is_args$args; } # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /qq/qq/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/qq/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/qq/assets/.+\.php(/|$) { deny all; } } location /weibo { alias E:/wwwroot/channel-pub-api-feature-task-group/weibo/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /weibo/ { # return 301 /weibo; #} # prevent the directory redirect to the URL with a trailing slash location = /weibo { # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /weibo/weibo/web/index.php$is_args$args; } # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /weibo/weibo/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/weibo/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/weibo/assets/.+\.php(/|$) { deny all; } } location /wx { alias E:/wwwroot/channel-pub-api-feature-task-group/wx/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /wx/ { # return 301 /wx; #} # prevent the directory redirect to the URL with a trailing slash location = /wx { # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /wx/wx/web/index.php$is_args$args; } # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /wx/wx/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/wx/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/wx/assets/.+\.php(/|$) { deny all; } } location ~ ^/.+\.php(/|$) { rewrite (?!^/((api|baijia|customize|netease|qq|weibo|wx)/web|baijia|customize|netease|qq|weibo|wx))^ /api/web$uri break; rewrite (?!^/baijia/web)^/baijia(/.+)$ /baijia/web$1 break; rewrite (?!^/customize/web)^/customize(/.+)$ /customize/web$1 break; rewrite (?!^/netease/web)^/netease(/.+)$ /netease/web$1 break; rewrite (?!^/qq/web)^/qq(/.+)$ /qq/web$1 break; rewrite (?!^/weibo/web)^/weibo(/.+)$ /weibo/web$1 break; rewrite (?!^/wx/web)^/wx(/.+)$ /wx/web$1 break; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $fastcgi_script_name =404; } location ~ /\. { deny all; } } ## LOCALHOST API ## server { charset utf-8; client_max_body_size 200m; client_body_buffer_size 1024k; fastcgi_read_timeout 180s; listen 81; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name localhost; root E:/wwwroot/channel-pub-api-feature-task-group; index index.php; access_log logs/localhost.access.log; error_log logs/localhost.error.log; location / { root E:/wwwroot/channel-pub-api-feature-task-group/api/web; try_files $uri $uri/ /api/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/assets/.+\.php(/|$) { deny all; } } location /baijia { alias E:/wwwroot/channel-pub-api-feature-task-group/baijia/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /baijia/ { # return 301 /baijia; #} # prevent the directory redirect to the URL with a trailing slash location = /baijia { # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /baijia/baijia/web/index.php$is_args$args; } # if your location is "/baijia", try use "/baijia/baijia/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /baijia/baijia/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/baijia/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/baijia/assets/.+\.php(/|$) { deny all; } } location /customize { alias E:/wwwroot/channel-pub-api-feature-task-group/customize/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /customize/ { # return 301 /customize; #} # prevent the directory redirect to the URL with a trailing slash location = /customize { # if your location is "/customize", try use "/customize/customize/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /customize/customize/web/index.php$is_args$args; } # if your location is "/customize", try use "/customize/customize/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /customize/customize/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/customize/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/customize/assets/.+\.php(/|$) { deny all; } } location /netease { alias E:/wwwroot/channel-pub-api-feature-task-group/netease/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /netease/ { # return 301 /netease; #} # prevent the directory redirect to the URL with a trailing slash location = /netease { # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /netease/netease/web/index.php$is_args$args; } # if your location is "/netease", try use "/netease/netease/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /netease/netease/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/netease/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/netease/assets/.+\.php(/|$) { deny all; } } location /qq { alias E:/wwwroot/channel-pub-api-feature-task-group/qq/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /qq/ { # return 301 /qq; #} # prevent the directory redirect to the URL with a trailing slash location = /qq { # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /qq/qq/web/index.php$is_args$args; } # if your location is "/qq", try use "/qq/qq/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /qq/qq/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/qq/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/qq/assets/.+\.php(/|$) { deny all; } } location /weibo { alias E:/wwwroot/channel-pub-api-feature-task-group/weibo/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /weibo/ { # return 301 /weibo; #} # prevent the directory redirect to the URL with a trailing slash location = /weibo { # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /weibo/weibo/web/index.php$is_args$args; } # if your location is "/weibo", try use "/weibo/weibo/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /weibo/weibo/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/weibo/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/weibo/assets/.+\.php(/|$) { deny all; } } location /wx { alias E:/wwwroot/channel-pub-api-feature-task-group/wx/web/; # redirect to the URL without a trailing slash (uncomment if necessary) #location = /wx/ { # return 301 /wx; #} # prevent the directory redirect to the URL with a trailing slash location = /wx { # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri /wx/wx/web/index.php$is_args$args; } # if your location is "/wx", try use "/wx/wx/web/index.php$is_args$args" # bug ticket: https://trac.nginx.org/nginx/ticket/97 try_files $uri $uri/ /wx/wx/web/index.php$is_args$args; # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary) #location ~ ^/wx/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ { # log_not_found off; # access_log off; # try_files $uri =404; #} location ~ ^/wx/assets/.+\.php(/|$) { deny all; } } location ~ ^/.+\.php(/|$) { rewrite (?!^/((api|baijia|customize|netease|qq|weibo|wx)/web|baijia|customize|netease|qq|weibo|wx))^ /api/web$uri break; rewrite (?!^/baijia/web)^/baijia(/.+)$ /baijia/web$1 break; rewrite (?!^/customize/web)^/customize(/.+)$ /customize/web$1 break; rewrite (?!^/netease/web)^/netease(/.+)$ /netease/web$1 break; rewrite (?!^/qq/web)^/qq(/.+)$ /qq/web$1 break; rewrite (?!^/weibo/web)^/weibo(/.+)$ /weibo/web$1 break; rewrite (?!^/wx/web)^/wx(/.+)$ /wx/web$1 break; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9001; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $fastcgi_script_name =404; } location ~ /\. { deny all; } } ## MISC ## ### WWW Redirect ### server { listen 80; server_name channel-pub-api.localhost; return 301 http://www.channel-pub-api.localhost$request_uri; } |
3、新开 PowerShell 窗口,执行 php-cgi.exe -b 127.0.0.1:9001-c C:/php-7.2.14/php.ini,如图4
4、Nginx + php-fpm 在 Windows 10 下的情况表现,当在一个请求(http://api.channel-pub-api.localhost)中 CURL 另一个请求(http://localhost:81)时,响应成功,如图5
5、查看具体的请求发起时间节点,虽然是并行请求,但是实际表现上却是串行的。即一个请求完毕后,再执行下一个请求。其总体响应时间长度为:21.75s。如图6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 10:37:26.340 info yii\httpclient\StreamTransport::send POST http://localhost:81/baijia/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac62 Content-Type: application/json; charset=UTF-8 10:37:29.461 info yii\httpclient\StreamTransport::send POST http://localhost:81/netease/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac62 Content-Type: application/json; charset=UTF-8 10:37:32.732 info yii\httpclient\StreamTransport::send POST http://localhost:81/weibo/v1/articles/toutiao?group_id=015ce30b116ce86058fa6ab4fea4ac62 Content-Type: application/json; charset=UTF-8 10:37:35.757 info yii\httpclient\StreamTransport::send POST http://localhost:81/qq/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac62 Content-Type: application/json; charset=UTF-8 10:37:38.533 info yii\httpclient\StreamTransport::send POST http://localhost:81/qq/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac62 Content-Type: application/json; charset=UTF-8 10:37:41.132 info yii\httpclient\StreamTransport::send POST http://localhost:81/wx/v1/wx-articles/article?group_id=015ce30b116ce86058fa6ab4fea4ac62 Content-Type: application/json; charset=UTF-8 10:37:44.207 info yii\httpclient\StreamTransport::send POST http://localhost:81/customize/v1/articles/standard?group_id=015ce30b116ce86058fa6ab4fea4ac62 Content-Type: application/json; charset=UTF-8 |
6、决定分析测试 Nginx + php-fpm 在 Windows 10 下的串行表现。新建 phpinfo.php(延时 30 秒写入日志)、phpinfo1.php(延时 5 秒写入日志),在浏览器中先打开 phpinfo.php、然后再迅速打开 phpinfo1.php,间隔时间约为 1 秒左右。
phpinfo.php
1 2 3 4 5 | <?php sleep(30); file_put_contents ( 'E:/wwwroot/channel-pub-api/console/runtime/logs/sleep-0-' . time() . '.txt' , time()); phpinfo(); ?> |
phpinfo1.php
1 2 3 4 5 | <?php sleep(5); file_put_contents ( 'E:/wwwroot/channel-pub-api/console/runtime/logs/sleep-1-' . time() . '.txt' , time()); phpinfo(); ?> |
7、在打开 phpinfo.php 后,其大约加载了 30 秒左右的时间长度。在打开 phpinfo1.php 后,其大约加载了 35 秒左右的时间长度(如果支持并行,则加载时间预计为 5 秒左右。如果不支持并行,仅支持串行,则加载时间预计为 35 秒左右,其中 30 秒为等待 phpinfo.php 运行结束的时间,只有当 phpinfo.php 运行结束后,9001 端口才可用,5 秒为 phpinfo1.php 自身运行的时间)。如图7
8、分别查看生成的日志文件的创建时间。可以确定 phpinfo1.php 的日志文件的创建时间晚于 phpinfo.php 的日志文件的创建时间,精确为 5 秒钟。由此可以确定,Nginx + php-fpm 在 Windows 10 下,是仅支持串行请求的。如图8
1 2 | sleep-0-1585200354.txt sleep-1-1585200359.txt |
9、开发环境的部署方案为:CentOS + Nginx + php-fpm。重复第 6、7、8 步骤。分别查看生成的日志文件的创建时间。可以确定 phpinfo1.php 的日志文件的创建时间早于 phpinfo.php 的日志文件的创建时间,精确为 23 秒钟,虽然其晚于 phpinfo.php 开始运行。由此可以确定,Nginx + php-fpm 在 CentOS 7 下,是支持并行请求的。如图9
1 2 | sleep-0-1585202045.txt sleep-1-1585202022.txt |
10、编辑 Nginx 配置文件,修改 server_name 的值:api.channel-pub.wjdev.chinamcloud.cn localhost,以在一个请求(https://api.channel-pub.wjdev.chinamcloud.cn)中 CURL 另一个请求(http://localhost)(总计请求次数为 7),直接请求本机,以节省网络开销。其总体响应时间长度为:1956ms,2 秒左右,符合预期。如图10
11、直接请求本机,其并发请求数受限于 php-fpm.conf 中的 pm.max_children 值。现在默认设置为:40。子进程的数量固定为 40 个。当在一个请求(https://api.channel-pub.wjdev.chinamcloud.cn)中 CURL 另一个请求(http://localhost)的数量为 52 时,其总体响应时间长度为:6.00s。如图11
12、当请求数量为 42 时,其总体响应时间长度为:4.73s。当请求数量为 35 时,其总体响应时间长度为:4.39s。当请求数量为 30 时,其总体响应时间长度为:3.79s。当请求数量为 25 时,其总体响应时间长度为:2.98s。当请求数量为 20 时,其总体响应时间长度为:2.85s。当请求数量为 15 时,其总体响应时间长度为:2.36s。当请求数量为 10 时,其总体响应时间长度为:2.21s。
13、在服务器上 curl,查看 php-fpm 的状态页。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@5b9088596e62 /]# curl http://127.0.0.1/status pool: www process manager: static start time: 26/Mar/2020:13:50:05 +0800 start since: 4603 accepted conn: 516 listen queue: 0 max listen queue: 0 listen queue len: 128 idle processes: 39 active processes: 1 total processes: 40 max active processes: 10 max children reached: 0 slow requests: 0 |
14、最后分析测试的结果: Windows + Nginx + php-fpm(串行)、CentOS + Nginx + php-fpm(并行)、MacOS + Nginx + php-fpm(并行)、MacOS + Apache(并行)。
近期评论