关于在 mac 下 PHP -fpm 无法访问的问题[救救孩子吧]

47 天前
 fibroblast

关于在 mac 下 php-fpm 无法访问的问题


php 8.2 brew 本地安装 nginx 是 docker 请排除 nginx 找不到 index.php 文件的问题 因为在 nginx html 目录下有个 demo.html 文件可以正常访问 即 静态资源可以加载

pm-conf

[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
[www]
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 20
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 10
request_slowlog_timeout = 30
slowlog = log/php-fpm-slow.log

nginx-conf

server {
    listen       80;	#监听 80 端口
    listen  [::]:80;
    server_name  localhost;		#也可以填写自己注册的域名
    location / {
        root   /usr/share/nginx/html;	#当前配置的页面文件根目录
        index  index.php index.html index.htm;	#添加 index.php 作为默认首页
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;		#错误页面设置
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # 与 php-fpm 通信的关键设置
    location ~ \.php$ {
         root   /usr/share/nginx/html;	#页面文件根目录
         fastcgi_pass   127.0.0.1:9000;	#php-fpm 的通信端口,由于已经将容器 9000 端口映射到了主机的 9000 端口,所以这里填“主机 ip:9000”也是可以的。
         fastcgi_index  index.php;		#默认主页文件设置
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
         include        fastcgi_params;
    }
}

nginx 报错

2024/05/14 03:46:10 [error] 25#25: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.65.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1:8088"

fpm 日志 只有启动

[14-May-2024 12:05:48] NOTICE: Terminating ...
[14-May-2024 12:05:48] NOTICE: exiting, bye-bye!
[14-May-2024 12:05:48] NOTICE: fpm is running, pid 18393
[14-May-2024 12:05:48] NOTICE: ready to handle connections

直接访问 http://127.0.0.1:9000 也不行 日志无东西

1692 次点击
所在节点    PHP
43 条回复
evam
47 天前
本地调试,brew 安装的 php ?
要不直接 php -S localhost:8087
julyclyde
44 天前
所以你想明白了吧
如果一开始你没用 docker ,啥麻烦都不会遇到
chaodada
19 天前
前段时间有折腾过这个环境。楼主可以看一下 https://www.amdzz.cn/article/72/mac-phpnginx

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1040588

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX