Nginx 使用上传进度模块时出现未知指令“upload_progress”

Nginx 使用上传进度模块时出现未知指令“upload_progress”

我正在尝试为托管在 nginx 中的 laravel 应用程序创建进度条功能。这是我第一次使用 nginx,发现为上传创建上传进度并不容易。正如本文所述教程创建这个的唯一方法是我们需要“nginx-upload-progress-module”。要安装这个模块,我按照这个步骤操作教程. 但是当我尝试测试 nginx 配置时我遇到了unknown directive "upload_progress"

这是我的配置:

upload_progress proxied 1m;

server {
 listen 80;
 listen [::]:80;
 server_name  mydomain.com;
 client_max_body_size 0;


 root /var/www/mydomain.com/public;

 index index.php index.html;

 location / {
      try_files $uri $uri/ /index.php$is_args$args;

      # track uploads in the 'proxied' zone
      # remember connections for 30s after they finished
        track_uploads proxied 30s;
 }

 location ^~ /progress {
        # report uploads tracked in the 'proxied' zone
         report_uploads proxied;
    }

 location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}

}

答案1

已修复apt update。可能是某个错误已通过更新修复。或者可能是因为我删除了 nginx 并随后安装了 nginx-extra,导致出现一些错误,需要更新才能修复。另外,我的配置有误,正确的配置如下:


upload_progress uploads 1m;

server {
  listen 80;
  listen [::]:80;
  server_name  example.com www.example.com;
  client_max_body_size 0;


root /var/www/example.com/public;

index index.php index.html;

location / {
   try_files $uri $uri/ /index.php$is_args$args;
}

location ^~ /progress {
     # report uploads tracked in the 'uploads' zone
     upload_progress_json_output;
     report_uploads uploads;
 }

location ~ \.php$ {

include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;

# track uploads in the 'uploads' zone
# remember connections for 30s after they finished
track_uploads uploads 30s;
}

}

相关内容