PHP-FPM 套接字权限

PHP-FPM 套接字权限

首先,我到处搜索并测试了所有东西,但仍然不起作用。我安装了php5-fpmnginx当我localhost 在浏览器中打开时,我看到这个页面:

Welcome to nginx!

因此现在使用 nginx 配置 php5-fpm 就可以了/etc/php5/fpm/pool.d/www.conf

  user = www-data
  group = www-data
  listen = /var/run/php5-fpm.sock
  listen.owner = www-data
  listen.group = www-data
  pm = dynamic
  pm.max_children = 5
  pm.start_servers = 2
  pm.min_spare_servers = 1
  pm.max_spare_servers = 3
  chdir = /

所有其他行都已被注释,这是 nginx 配置:

  upstream php {
        server unix:/var/run/php5-fpm.socket;
  }

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm index.php;

# Make site accessible from http://localhost/
server_name localhost;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
#   proxy_pass http://127.0.0.1:8080;    
#}

#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;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#   allow all;
#}
}

问题是当我尝试运行.php文件时nginx会下载.php文件而不是执行它。

答案1

PHP-FPM 套接字权限

请检查套接字是否具有适当的权限。

$ ll /var/run/php5-fpm.sock
srw-rw---- 1 www-data www-data 0 Aug  6 14:16 /var/run/php5-fpm.sock=

如果输出不同,可能会添加listen.mode = 0660到您的输出中。www.conf

可能相关:nginx 错误连接到 php5-fpm.sock 失败(13:权限被拒绝)

nginx 配置

  1. 这真的是你的文件所在的地方吗?

    root /usr/share/nginx/html;
    index index.html index.htm index.php;
    
  2. 这个块应该做什么?

      upstream php {
            server unix:/var/run/php5-fpm.socket;
      }
    
  3. 我建议将其try_files $uri =404;location ~ \.php$区块中移除。

  4. 为什么第 2 行和第 3 行的缩进与其他行不同?请注意,这会影响正确的配置,但这给人留下了它们是被粗心地粘贴在一起的印象。请提供您使用的说明的链接。

答案2

相关内容