摘要:昨天晚上忘記對(duì)開發(fā)環(huán)境做了什么改動(dòng),導(dǎo)致今天來(lái)了在進(jìn)行接口調(diào)試的時(shí)候提示這個(gè)大多數(shù)情況下來(lái)說(shuō)是一個(gè)很簡(jiǎn)單的問(wèn)題配置里面的錯(cuò)誤。然而我檢查了我的配置,發(fā)現(xiàn)并沒(méi)有什么問(wèn)題。
昨天晚上忘記對(duì)開發(fā)環(huán)境做了什么改動(dòng),導(dǎo)致今天來(lái)了在進(jìn)行接口調(diào)試的時(shí)候nginx提示"Primary script unknown",這個(gè)大多數(shù)情況下來(lái)說(shuō)是一個(gè)很簡(jiǎn)單的問(wèn)題:nginx配置里面的script_filename錯(cuò)誤。然而我檢查了我的nginx配置,發(fā)現(xiàn)并沒(méi)有什么問(wèn)題。
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; }
同時(shí),我也對(duì)這個(gè)配置進(jìn)行了驗(yàn)證,在http模塊的access日志格式配置里面加入請(qǐng)求文件名,并在sever模塊里面使用這個(gè)配置
log_format main "$remote_addr - $remote_user [$time_local] "$request" " "$status $body_bytes_sent "$http_referer" " ""$http_user_agent" "$http_x_forwarded_for" $document_uri $request_filename";
access_log "logs/frontapi.access.log" main;
下面是打印的日志,經(jīng)過(guò)驗(yàn)證,這個(gè)配置確實(shí)是沒(méi)有問(wèn)題的。
127.0.0.1 - - [18/Mar/2019:12:40:40 +0800] "GET /v1/product/search?category=2 HTTP/1.1" 404 27 "-" "PostmanRuntime/7.6.1" "-" /index.php /Users/xubandit/Documents/www/mmt/mmt-mall-php/frontapi/web/index.php ^C xubanditdeMacBook-Pro:logs xubandit$ ll /Users/xubandit/Documents/www/mmt/mmt-mall-php/frontapi/web/index.php -rwxr-xr-x 1 xubandit staff 570 3 9 16:39 /Users/xubandit/Documents/www/mmt/mmt-mall-php/frontapi/web/index.php
然后又查了php代碼,發(fā)現(xiàn)請(qǐng)求根本就沒(méi)有到php代碼這邊來(lái),也就是說(shuō)問(wèn)題出在了php-fpm,然后就想怎么對(duì)php-fpm進(jìn)行調(diào)試,查看了php-fpm的日志,發(fā)現(xiàn)日志里面只記錄了php-fpm master進(jìn)程的信息,子進(jìn)程里面進(jìn)行php處理的內(nèi)容是沒(méi)有日志的。
只能進(jìn)行進(jìn)程調(diào)試了,然而發(fā)現(xiàn)macos下面并沒(méi)有strace這個(gè)工具,好在有個(gè)替代品dtruss
xubanditdeMacBook-Pro:php-fpm.d xubandit$ sudo dtruss -p 13735 dtrace: system integrity protection is on, some features will not be available SYSCALL(args) = return poll(0x7FFEE3A437B0, 0x1, 0x1388) = 1 0 getrusage(0x0, 0x7FFEE3A43670, 0x0) = 0 0 getrusage(0xFFFFFFFFFFFFFFFF, 0x7FFEE3A43670, 0x0) = 0 0 dtrace: error on enabled probe ID 2174 (ID 159: syscall::read:return): invalid kernel access in action #12 at DIF offset 68 dtrace: error on enabled probe ID 2174 (ID 159: syscall::read:return): invalid kernel access in action #12 at DIF offset 68 dtrace: error on enabled probe ID 2174 (ID 159: syscall::read:return): invalid kernel access in action #12 at DIF offset 68 dtrace: error on enabled probe ID 2174 (ID 159: syscall::read:return): invalid kernel access in action #12 at DIF offset 68 dtrace: error on enabled probe ID 2174 (ID 159: syscall::read:return): invalid kernel access in action #12 at DIF offset 68 lstat64("/Users/xubandit/Documents/www/mmt/mmt-mall-php/frontapi/web/index.php