2016-03-14 258 views
3

在我的流浪者箱子上,centtos 7,我安装了php7.0.3和nginx 1.9.12。 php配置www.conf。此文件中的/usr/local/php/etc/php-fpm.d/目录,这样连接()到unix:/tmp/php-fpm.sock失败(2:没有这样的文件或目录)

user = www 
group = www 
;listen = /tmp/php-fpm.sock 
listen = 127.0.0.1:9000 
listen.owner = www 
listen.group = www 

和nginx的配置它的配置。/usr/local/nginx/conf/vhost /目录下的文件vm.demo.com.conf。它的配置是这样

server { 
    listen  80; 
    server_name vm.demo.com; 
    index index.html index.htm index.php; 
    root /data/wwwroot/demo; 

    location/{ 
     if (-f $request_filename/index.html){ 
      rewrite (.*) $1/index.html break; 
     } 
     if (-f $request_filename/index.php){ 
      rewrite (.*) $1/index.php; 
     } 
     if (!-f $request_filename){ 
      rewrite (.*) /index.php; 
     } 
    } 
    location ~ .*\.(php|php5)?$ { 
     #fastcgi_pass unix:/tmp/php-fpm.sock; 
     fastcgi_pass 127.0.0.1:9000; 

     fastcgi_index index.php; 
     include fastcgi.conf; 
    } 
    access_log logs/demo.log main; 
} 
在nginx的CONF

,如果我使用fastcgi_pass 127.0.0.1:9000和PHP-fpm.conf听127.0.0.1:9000,他们正在正常 错误,如果我使用socket配置:

PHP www.conf

user = www 
group = www 
listen = /tmp/php-fpm.sock 
listen.owner = www 
listen.group = www 

nginx的vm.demo.com.conf

location ~ .*\.(php|php5)?$ { 
     fastcgi_pass unix:/tmp/php-fpm.sock; 
     fastcgi_index index.php; 
     include fastcgi.conf; 
    } 

nginx显示502坏的网关。在nginx的error.log中显示这个。

2016/03/14 21:17:04 [crit] 4208#0: *5 connect() to unix:/tmp/php-fpm.sock failed (2: No such file or directory) while 
connecting to upstream, client: 192.168.1.101, server: vm.demo.com, request: "GET /test.php HTTP/1.1", 
upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "vm.demo.com" 
2016/03/14 21:17:04 [crit] 4208#0: *5 connect() to unix:/tmp/php-fpm.sock failed (2: No such file or directory) while 
connecting to upstream, client: 192.168.1.101, server: vm.demo.com, request: "GET /test.php HTTP/1.1", 
upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "vm.demo.com" 
2016/03/14 21:18:01 [crit] 4208#0: *5 connect() to unix:/tmp/php-fpm.sock failed (2: No such file or directory) while 
connecting to upstream, client: 192.168.1.101, server: vm.demo.com, request: "GET /test.php HTTP/1.1", 
upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "vm.demo.com" 

当我检查/tmp/php-fpm.sock文件,它是现有

[[email protected] vhost]# ll /tmp/php-fpm.sock 
srw-rw---- 1 www www 0 Mar 14 21:06 /tmp/php-fpm.sock 

这是PHP和Nginx的运行状态:

[[email protected] vhost]# systemctl status php-fpm.service 
● php-fpm.service - The PHP FastCGI Process Manager 
    Loaded: loaded (/etc/systemd/system/php-fpm.service; enabled; vendor preset: disabled) 
    Active: active (running) since Mon 2016-03-14 21:06:27 CST; 42min ago 
    Process: 4189 ExecStop=/bin/kill -SIGINT $MAINPID (code=exited, status=0/SUCCESS) 
Main PID: 4198 (php-fpm) 
    CGroup: /system.slice/php-fpm.service 
      ├─4198 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) 
      ├─4199 php-fpm: pool www 
      └─4200 php-fpm: pool www 

Mar 14 21:06:27 vbox1 systemd[1]: Started The PHP FastCGI Process Manager. 
Mar 14 21:06:27 vbox1 systemd[1]: Starting The PHP FastCGI Process Manager... 
[[email protected] vhost]# systemctl status nginx.service 
● nginx.service - nginx 
    Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: disabled) 
    Active: active (running) since Mon 2016-03-14 21:06:35 CST; 42min ago 
    Process: 4180 ExecStop=/usr/local/nginx/sbin/nginx -s quit (code=exited, status=0/SUCCESS) 
    Process: 4206 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS) 
Main PID: 4207 (nginx) 
    CGroup: /system.slice/nginx.service 
      ├─4207 nginx: master process /usr/local/nginx/sbin/nginx 
      ├─4208 nginx: worker process 
      └─4209 nginx: worker process 

Mar 14 21:06:35 vbox1 systemd[1]: Starting nginx... 
Mar 14 21:06:35 vbox1 systemd[1]: Started nginx. 

有人能帮助我吗?如果有人遇到同样的问题

+1

'nginx'是否也以用户'www'运行? –

+0

@RichardSmith是的。它是。[root @ vbox1 wmq]#ps aux | grep nginx root 4207 0.0 0.4 47644 2024? Ss 21:06 0:00 nginx:主进程/ usr/local/nginx/sbin/nginx www 6143 0.0 0.3 48036 1968? S 22:00 0:01 nginx:工作进程 www 6144 0.0 0.5 48428 2820? S 22:00 0:00 nginx:工作进程 – Johnny

回答

1

我发现一个配置(php5),继续使用unix套接字,不涉及编辑任何其他配置文件(nginx默认站点文件除外)。

location ~ \.php$ { 
fastcgi_pass unix:/run/php5-fpm.sock; 
fastcgi_index index.php; 
include fastcgi_params; 
# \Add following to use sqlite as db. 
fastcgi_param DB_CONNECTION sqlite; 

}

注: - Unix套接字是不是/run/php/(虽然它是PHP7)。 include fastcgi_params;是必需的,以防止php文件下载,而不是被解释。

为了完整起见,以下是我的整个默认文件。

index index.php index.html index.htm; 

server { 
    listen 80; 
    server_name sponk.co.uk; 

    rewrite_log on; 

    root /vagrant/public_html; 
    try_files $uri $uri/ /index.php$is_args$args; 

    location ~ \.php$ { 
    fastcgi_pass unix:/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
    } 

    location ~ /\.ht { 
    deny all; 
    } 

} 
5

我遇到了同样的问题。 而我只是改变套接字路径到另一个目录,但'/ tmp', 然后一切顺利。

+0

你如何做到这一点?它涉及什么? – User

+0

@User我确信套接字路径有问题我之前没有使用过vagrant,但一般在Linux上,套接字路径在'/ var/run/php/php-fpm.sock'下,我看到的还有他是使用'php7.0',所以fpm套接字应该是'php7.0-fpm.sock' –

0

您可以尝试将/usr/local/php/etc/php-fpm.d/www.conf中的用户更改为nginx并重新启动服务。

user = nginx 
group = nginx 
listen = /tmp/php-fpm.sock 
相关问题