Nginx + PHP-FPM serial, parallel support analysis, test and solution of serial and parallel support under Windows 10 and CentOS 8
1. Nginx + php-fpm in the case of Windows 10, when in a request (http://api.channel-pub-api.localhost)中curl another request (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! . as shown in Figure 1
{
"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. Edit the Nginx configuration file and copy the server: API to the server: localhost API. Adjust Listen 81, server_name localhost, fastcgi_pass 127.0.0.1:9001. A total of 3 configuration values. Figure 2, Figure 3
## 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. Open a new PowerShell window and execute php-cgi.exe -b 127.0.0.1:9001-c c:/php-7.2.14/php.ini, as shown in Figure 4
4. Nginx + php-fpm in the case of Windows 10, when in a request (http://api.channel-pub-api.localhost)中curl another request (http://localhost:81)时,响应成功,如图5
5. Check the time node for the specific request to initiate. Although it is a parallel request, the actual performance is serial. That is, after a request is completed, the next request is executed. Its overall response time is: 21.75s. as shown in Figure 6
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. Decide analysis test Nginx + PHP-FPM serial performance under Windows 10. Create phpinfo.php (delay 30 seconds to write logs), phpinfo1.php (delay for 5 seconds to write logs), first open phpinfo.php in the browser, and then open them quickly phpinfo1.php, the interval is about 1 second.
phpinfo.php
phpinfo1.php
7. After opening phpinfo.php, it has been loaded for about 30 seconds. After opening phpinfo1.php, it loads about 35 seconds for a length of about 35 seconds (if parallelism is supported, the loading time is expected to be about 5 seconds. If parallelism is not supported, only the loading time is expected to be 35 30 seconds or so, 30 seconds is the time to wait for phpinfo.php to end, only when phpinfo.php runs, port 9001 is available, 5 seconds is phpinfo1.php time of its own operation). as shown in Figure 7
8. Check the creation time of the generated log files separately. It can be determined that the log file of phpinfo1.php is created later than the log file of phpinfo.php, which is precisely 5 seconds. From this, it can be determined that Nginx + PHP-FPM only supports serial requests under Windows 10. as shown in Figure 8
sleep-0-1585200354.txt
sleep-1-1585200359.txt
9. The deployment scheme of the development environment is: CentOS + Nginx + PHP-FPM. Repeat steps 6, 7, and 8. View the creation time of the generated log files separately. It can be determined that the log file of phpinfo1.php is created earlier than the log file of phpinfo.php, which is precisely 23 seconds, although it starts to run after phpinfo.php. It can be determined that Nginx + PHP-FPM supports parallel requests under CentOS 7. as shown in Figure 9
sleep-0-1585202045.txt
sleep-1-1585202022.txt
10. Edit the nginx configuration file and modify the value of server_name: api.channel-pub.wjdev.chinamcloud.cn localhost to a request (https://api.channel-pub.wjdev.chinamcloud.cn)中curl another request (http://localhost)(总计请求次数为7), directly request this machine to save network overhead. Its overall response time is: 1956ms, about 2 seconds, in line with expectations. As shown in Figure 10
11. Request the machine directly, and the number of concurrent requests is limited by the value of pm.max_children in php-fpm.conf. Now the default setting is: 40. The number of subprocesses is fixed to 40. when in a request (https://api.channel-pub.wjdev.chinamcloud.cn)中curl another request (http://localhost)的数量为At 52, the overall response time length is: 6.00s. as shown in Figure 11
12. When the number of requests is 42, its overall response time is: 4.73s. When the number of requests is 35, its overall response time is: 4.39s. When the number of requests is 30, its overall response time is: 3.79s. When the number of requests is 25, its overall response time is: 2.98s. When the number of requests is 20, its overall response time is: 2.85s. When the number of requests is 15, its overall response time is: 2.36s. When the number of requests is 10, its overall response time is: 2.21s.
13. CURL on the server, check the status page of php-fpm.
[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. The results of the final analysis test: Windows + Nginx + PHP-FPM (serial), CentOS + Nginx + PHP-FPM (parallel), macOS + Nginx + php-fpm (parallel), macOS + Apache (parallel).










