使用 nginx 和 php-fpm 托管 Ampache(流媒体服务)时出现空白页

使用 nginx 和 php-fpm 托管 Ampache(流媒体服务)时出现空白页

我的 nginx vhost 缺少配置。每当我访问托管的 ampache url 时,我都会得到一个空白页。ampache 日志、nginx 日志或 php-fpm 日志中均未记录任何错误。ampache 访问日志和 php-fpm 日志中记录了访问,状态为 200。这是我的 nginx vhost 配置:

server {
  listen 80;
  server_name ampache.mydomain.com;
  root /var/www/ampache.mydomain.com/htdocs/ampache/;

  access_log  /var/log/nginx/ampache.access.log;
  error_log   /var/log/nginx/ampache.error.log;
  index index.php;

  # Rewrite rule for Subsonic backend
  if ( !-d $request_filename ) {
    rewrite ^/rest/(.*).view$ /rest/index.php?action=$1 last;
    rewrite ^/rest/fake/(.+)$ /play/$1 last;
  }

  # Rewrite rule for Plex backend
  if ( !-d $request_filename ) {
    rewrite ^/plex/(.*)$ /plex/index.php?action=$1 last;
  }

  # Rewrite rule for Channels
  if (!-d $request_filename){
    rewrite ^/channel/([0-9]+)/(.*)$ /channel/index.php?channel=$1&target=$2 last;
  }

  # Beautiful URL Rewriting
  rewrite ^/play/ssid/(\w+)/type/(\w+)/oid/([0-9]+)/uid/([0-9]+)/name/(.*)$ /play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&name=$5 last;

  location /rest {
    limit_except GET POST {
      deny all;
    }
  }

  location /plex {
    limit_except GET POST {
      deny all;
    }
  }

  location ^~ /bin/ {
    deny all;
    return 403;
  }

  location ^~ /config/ {
    deny all;
    return 403;
  }

  location / {
    limit_except GET POST HEAD{
      deny all;
    }
  }

  location ~ ^/.*.php {
    # try_files $uri = 404;
    # try_files $1 = 404;
    fastcgi_index index.php;
    include fastcgi_params;
    # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    # fastcgi_param PATH_INFO $2;
    # fastcgi_param HTTPS on;
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    fastcgi_pass unix:/run/php-fpm.socket;
  }

  # Rewrite rule for WebSocket
  location /ws {
    rewrite ^/ws/(.*) /$1 break;
    # proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8100/;
  }
}

答案1

我可以像这样修复我的错误配置

...
location ~ \.php$ {
  try_files  $uri =404;
  fastcgi_pass unix:/run/php-fpm.socket;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  include        fastcgi_params;
 }
 ...

相关内容