昨天晚上忘記對開發環境作了什麼改動,致使今天來了在進行接口調試的時候nginx提示"Primary script unknown",這個大多數狀況下來講是一個很簡單的問題:nginx配置裏面的script_filename錯誤。然而我檢查了個人nginx配置,發現並無什麼問題。php
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; }
同時,我也對這個配置進行了驗證,在http模塊的access日誌格式配置裏面加入請求文件名,並在sever模塊裏面使用這個配置nginx
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;
下面是打印的日誌,通過驗證,這個配置確實是沒有問題的。web
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代碼,發現請求根本就沒有到php代碼這邊來,也就是說問題出在了php-fpm,而後就想怎麼對php-fpm進行調試,查看了php-fpm的日誌,發現日誌裏面只記錄了php-fpm master進程的信息,子進程裏面進行php處理的內容是沒有日誌的。macos
只能進行進程調試了,然而發現macos下面並無strace這個工具,好在有個替代品dtrussapi
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\0", 0x7FFEE3A52E30, 0x0) = -1 Err#13 stat64("/Users/xubandit/Documents/www/mmt/mmt-mall-php/frontapi/web\0", 0x7FFEE3A53980, 0x0) = -1 Err#13 stat64("/Users/xubandit/Documents/www/mmt/mmt-mall-php/frontapi\0", 0x7FFEE3A53980, 0x0) = -1 Err#13 stat64("/Users/xubandit/Documents/www/mmt/mmt-mall-php\0", 0x7FFEE3A53980, 0x0) = -1 Err#13 stat64("/Users/xubandit/Documents/www/mmt\0", 0x7FFEE3A53980, 0x0) = -1 Err#13 stat64("/Users/xubandit/Documents/www\0", 0x7FFEE3A53980, 0x0) = -1 Err#13 stat64("/Users/xubandit/Documents\0", 0x7FFEE3A53980, 0x0) = 0 0 stat64("/Users/xubandit\0", 0x7FFEE3A53980, 0x0) = 0 0 stat64("/Users\0", 0x7FFEE3A53980, 0x0) = 0 0 stat64("\0", 0x7FFEE3A53980, 0x0) = -1 Err#2
經過調試發現php-fpm是正常接收到了文件這個參數,只是訪問的時候報錯了。而後檢查配置文件發現php-fpm是nobody:nobody用戶運行的,文件的owner是xubandit:staff,訪問權限有問題,因爲是我本地電腦,因此就把php-fpm運行的用戶改爲了xubandit:staff。問題到這裏就解決了php-fpm
tips:爲了strace方便,我把php-fpm配置進行了修改,讓php-fpm只fork出一個子進程處理全部的請求工具
pm.max_children = 1 pm.start_servers = 1 pm.min_spare_servers = 1 pm.max_spare_servers = 1