小编典典

NGINX:connect()到Unix:/var/run/php7.0-fpm.sock失败(2:没有这样的文件或目录)

linux

我试图在使用php7为Ubuntu
16.04调整它时遵循此Ansible教程。在此消息下方,您将找到我的Ansible文件。运行它并尝试在浏览器中访问该页面后,我得到了404,以及nginx错误日志中的以下内容:

2016/10/15 13:13:20 [crit] 28771#28771:* 7对unix的connect():/ var / run /
php7.0-fpm.sock在连接到时失败(2:没有这样的文件或目录)上游,客户端:93.xxx.xxx.xx,服务器:95.xx.xx.xx,请求:“
GET / HTTP / 1.1”,上游:“ fastcgi:// unix:/var/run/php7.0- fpm.sock:”,主机:“
95.xx.xx.xx”

因此,我检查了套接字文件是否存在,并且似乎存在,但是ls行为异常:

$ 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

ls如果我按部分名称搜索php套接字文件,而我列出php7的名称甚至全名都找不到套接字文件,为什么找不到套接字文件php7.0-fpm.sock

最重要的是,我如何使用Nginx进行这项工作?欢迎所有提示!

下面我粘贴了Ansible文件

---
- 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

阅读 617

收藏
2020-06-07

共1个答案

小编典典

有同样的问题。解决方案很容易。

在nginx conf文件中,您尝试上游

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

正确的路径是

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


文档中对此有提及

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

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

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

2020-06-07