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

  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

相關內容