【问题标题】:Socket operation on non-socket nginx error with Laravel php使用 Laravel php 对非套接字 nginx 错误进行套接字操作
【发布时间】:2018-06-10 20:32:52
【问题描述】:

我只是想在我的 OSX 上的 nginx 上运行 php。

设置

我的php-fpm.conf 文件
我的www.conf 文件
在我的 nginx.conf 文件中,我得到了这个:

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

错误

每次我访问我的服务器时都会收到此错误:

2017/12/31 01:45:25 [crit] 1102#0: *2 connect() 到 unix:/var/run/php-fpm.sock 失败(38:非套接字上的套接字操作)而连接到上游,客户端::::1,服务器:默认,请求:“POST /api/users/login HTTP/1.1”,上游:“fastcgi://unix:/var/run/php-fpm.sock:” , 主机: "localhost:8000"

我该怎么做才能解决这个问题?

更新

我意识到在我的php-fpm.d/www.conf 里面我得到了这条线

listen = 127.0.0.1:9000

所以我更新了我的 nginx 配置文件:

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php;
        include fastcgi_params;
    }

但现在我收到此错误:

2017/12/31 02:07:24 [error] 1429#0: *2 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: ::1, server: default, request :“POST /api/users/login HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“localhost:8000”

更新 3

来自this answer我将这个添加到nginx conf:

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php;
        include fastcgi.conf;
    }

fastcgi.conf 有这个:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

但还是一样的错误信息

【问题讨论】:

    标签: php macos sockets nginx


    【解决方案1】:

    解决方案很简单.. nginx 正在寻找我的 index.php.. 我提供了我的 laravel 项目的根目录,而实际上我应该像这样将公共目录放在 laravel 中:

    http {
        server {
            listen 8000 default_server;
            listen [::]:8000 default_server;
            server_name default;
            root /path/to/my/laravel/project/public/index.php; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 1970-01-01
      相关资源
      最近更新 更多