前言
在學(xué)習(xí)php的時候蓖柔,遇到了一個花了好幾個小時才解決的坑咨演,在這里先粗略的記錄下闸昨。
nginx配置
我的nginx配置文件目錄是?/usr/local/etc/nginx
nginx我使用的是默認的,沒有做任何更改,查看nginx.conf,倒數(shù)第二行是這樣寫的
```
include servers/*;
```
由于我要配置多站點饵较,所以創(chuàng)建了servers/nginx-test.conf(servers 目錄不要創(chuàng)建任何不符合nginx語法的文件溉跃,否則,啟動nginx會報錯)
/usr/local/etc/nginx/servers/nginx-test.conf
```
server {
? ? listen? ? ? 80;? ? ? ? ? ? ? ? ? ? ? ? # 監(jiān)聽端口
? ? server_name kutu.com;? ? # 站點域名
? ? root? /Users/huansnow/Documents/php_work/phpinfo;? ? ? ? ? ? ? # 站點根目錄
? ? # PHP配置
? ? location ~ \.php$ {
? ? ? ? fastcgi_pass 127.0.0.1:9000;
? ? ? ? index? index.php index.html index.htm;
? ? ? ? fastcgi_param? SCRIPT_FILENAME? $document_root$fastcgi_script_name;
? ? ? ? include? ? ? ? fastcgi_params;
? ? }
error_log /usr/local/etc/nginx/log/test.log error;
```
fastcgi_pass 這個配置需要啟動php-fpm的, 找不到php-fpm文件可以使用
```
find / -name 'php-fpm'
```
查找
執(zhí)行php-fpm
報錯
```
[07-Aug-2019 06:17:24] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)
[07-Aug-2019 06:17:24] ERROR: failed to load configuration file '/private/etc/php-fpm.conf'
[07-Aug-2019 06:17:24] ERROR: FPM initialization failed
```
到/private/etc/ 復(fù)制一份
```
cd?/private/etc/
cp?php-fpm.conf.defaul?php-fpm.conf
```
又有報錯8娉!G段4蛲荨!
```
[06-Aug-2019 22:21:33] WARNING: Nothing matches the include pattern '/private/etc/php-fpm.d/*.conf' from /private/etc/php-fpm.conf at line 125.
[06-Aug-2019 22:21:33] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
[06-Aug-2019 22:21:33] ERROR: failed to post process the configuration
[06-Aug-2019 22:21:33] ERROR: FPM initialization failed
```
修改php-fpm.conf
```
error_log = /usr/local/etc/nginx/log/php-fpm.log
```
又又又報錯
```
[06-Aug-2019 22:26:44] WARNING: Nothing matches the include pattern '/private/etc/php-fpm.d/*.conf' from /private/etc/php-fpm.conf at line 125.
[06-Aug-2019 22:26:44] ERROR: No pool defined. at least one pool section must be specified in config file
[06-Aug-2019 22:26:44] ERROR: failed to post process the configuration
[06-Aug-2019 22:26:44] ERROR: FPM initialization failed
```
繼續(xù)百度
```
cd?/etc/php-fpm.d
sudo cp www.conf.default www.conf
sudo php-fmp
```
終于ok
啟動nginx
```
#檢測ngixn配置
nginx -t?
#啟動
nginx
#停止
nginx -s stop
#重啟
nginx -s reload
```
訪問站點發(fā)現(xiàn)訪問php文件都404,
查看日志都是
```
2019/08/06 13:42:09 [error] 31423#0: *435 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: kutu.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "kutu.com"
2019/08/06 13:42:09 [error] 31423#0: *435 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: kutu.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "kutu.com"
```
然后百度解決逆粹,發(fā)現(xiàn)大部分都是博客都抄來抄去募疮,根本沒法解決問題,后來有人提到可能是目錄權(quán)限問題
于是將?/Users/huansnow/Documents/php_work/phpinfo 從根目錄開始每個開始全都改成777
```
chmod 777 目錄
```
文章僅做個人解決問題記錄僻弹,沒啥參考意義