NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) [英] NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)

查看:37
本文介绍了NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关注 这个 Ansible 教程,同时使用 php7 为 Ubuntu 16.04 调整它.在此消息下方,您将找到我的 Ansible 文件.运行它并尝试在浏览器中访问该页面后,我收到 404,并且在 nginx 错误日志中显示以下内容:

I'm trying to follow this Ansible tutorial while adjusting it for Ubuntu 16.04 with php7. Below this message you'll find my Ansible file. After running it and trying to visit the page in the browser I get a 404, and the following in the nginx error logs:

2016/10/15 13:13:20 [暴击] 28771#28771:*7 connect() tounix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)连接上游时,客户端:93.xxx.xxx.xx,服务器:95.xx.xx.xx,请求:GET/HTTP/1.1",上游:fastcgi://unix:/var/run/php7.0-fpm.sock:",主机:95.xx.xx.xx"

2016/10/15 13:13:20 [crit] 28771#28771: *7 connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 93.xxx.xxx.xx, server: 95.xx.xx.xx, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php7.0-fpm.sock:", host: "95.xx.xx.xx"

所以我检查了套接字文件是否存在,它似乎存在,但是 ls 表现得很奇怪:

So I checked if the socket file exists, and it seems to exist, but ls behaves weird:

$ sudo ls -l /var/run/php
total 4
-rw-r--r-- 1 root     root     5 Oct 15 13:00 php7.0-fpm.pid
srw-rw---- 1 www-data www-data 0 Oct 15 13:00 php7.0-fpm.sock
$ sudo ls -l /var/run/php7
ls: cannot access '/var/run/php7': No such file or directory
$ sudo ls -l /var/run/php7.0-fpm.sock
ls: cannot access '/var/run/php7.0-fpm.sock': No such file or directory

为什么如果我按名称php的一部分搜索它,ls可以找到套接字文件,而当我列出超过那个时却找不到套接字文件php7 甚至全名php7.0-fpm.sock?

Why can ls find the socket file if I search it by part of the name php while it cannot find the socket file when I list more than that php7 or even the full name php7.0-fpm.sock?

最重要的是,我怎样才能在 Nginx 上做到这一点?欢迎所有提示!

And most importantly, how can I make this work with nginx? All tips are welcome!

下面我粘贴了我的 Ansible 文件

below I pasted my Ansible file

---
- hosts: php
  become: true

  tasks:
  - name: install packages
    apt: name={{ item }} update_cache=yes state=latest
    with_items:
      - git
      - mcrypt
      - nginx
      - php-cli
      - php-curl
      - php-fpm
      - php-intl
      - php-json
      - php-mcrypt
      - php-mbstring
      - php-sqlite3
      - php-xml
      - sqlite3

  - name: enable mbstring
    shell: phpenmod mbstring
    notify:
      - restart php7.0-fpm
      - restart nginx

  - name: create /var/www/ directory
    file: dest=/var/www/ state=directory owner=www-data group=www-data mode=0700

  - name: Clone git repository
    git: >
      dest=/var/www/laravel
      repo=https://github.com/laravel/laravel.git
      update=no
    become: true
    become_user: www-data
    register: cloned

  - name: install composer
    shell: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    args:
      creates: /usr/local/bin/composer

  - name: composer create-project
    composer: command=create-project working_dir=/var/www/laravel optimize_autoloader=no
    become: true
    become_user: www-data
    when: cloned|changed

  - name: set APP_DEBUG=false
    lineinfile: dest=/var/www/laravel/.env regexp='^APP_DEBUG=' line=APP_DEBUG=false

  - name: set APP_ENV=production
    lineinfile: dest=/var/www/laravel/.env regexp='^APP_ENV=' line=APP_ENV=production

  - name: Configure nginx
    template: src=nginx.conf dest=/etc/nginx/sites-available/default
    notify:
      - restart php5-fpm
      - restart nginx

  handlers:
    - name: restart php7.0-fpm
      service: name=php7.0-fpm state=restarted

    - name: restart nginx
      service: name=nginx state=restarted

    - name: reload nginx
      service: name=nginx state=reloaded

推荐答案

遇到了同样的问题.解决方法很简单.

Had the same problem. Solution is very easy.

在 nginx conf 文件中,您正在尝试向上游发送

In nginx conf file you are trying upstreaming to

unix:/var/run/php7.0-fpm.sock

正确的路径是

unix:/var/run/php/php7.0-fpm.sock

文档

Nginx 使用 Unix 域套接字与 PHP-FPM 通信.插座映射到文件系统上的路径,我们的 PHP 7 安装使用新的默认路径:

Nginx communicates with PHP-FPM using a Unix domain socket. Sockets map to a path on the filesystem, and our PHP 7 installation uses a new path by default:

PHP 5 /var/run/php5-fpm.sock

PHP 7 /var/run/php/php7.0-fpm.sock

这篇关于NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆