为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel Nginx PHP-FPM 特定 url client_max_body_size

Laravel Nginx PHP-FPM 特定 url client_max_body_size

PHP
DIEA 2022-10-14 14:42:36
我在 Nginx PHP-FPM 之上运行我的 Laravel 应用程序。我有一个功能请求,要求网页允许最多 100 MB 的视频上传。我不想要的是打开整个请求以允许 100MB。这是我最初的 nginx 设置:server {    listen 80;    listen [::]:80;    root /path-to-web/public;    index index.php index.html;    server_name www.myweb.com;    client_max_body_size 18m;    location / {        try_files $uri $uri/ /index.php?$query_string;    }    proxy_connect_timeout 180s;    proxy_send_timeout 180s;    proxy_read_timeout 180s;    fastcgi_send_timeout 180s;    fastcgi_read_timeout 180s;    # pass the PHP scripts to FastCGI server    #    location ~ \.php$ {        include snippets/fastcgi-php.conf;        fastcgi_pass unix:/run/php/php7.2-fpm.sock;        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;        fastcgi_param DOCUMENT_ROOT $realpath_root;        fastcgi_param PHP_VALUE "newrelic.appname=www.myweb.com";    }}server {    listen 443;    listen [::]:443;    ssl on;    ssl_certificate /path-to-cert/cert.pem;    ssl_certificate_key /path-to-cert/cert.key;    root /path-to-web/public;    index index.php index.html;    server_name www.myweb.com;    client_max_body_size 18m;    location / {        try_files $uri $uri/ /index.php?$query_string;    }    proxy_connect_timeout 180s;    proxy_send_timeout 180s;    proxy_read_timeout 180s;    fastcgi_send_timeout 180s;    fastcgi_read_timeout 180s;    # pass the PHP scripts to FastCGI server    #    location ~ \.php$ {        include snippets/fastcgi-php.conf;        fastcgi_pass unix:/run/php/php7.2-fpm.sock;        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;        fastcgi_param DOCUMENT_ROOT $realpath_root;        fastcgi_param PHP_VALUE "newrelic.appname=www.myweb.com";    }}
查看完整描述

1 回答

?
慕虎7371278

TA贡献1802条经验 获得超4个赞

恢复到您的原始配置,只更改这些:


 location / {

        client_max_body_size 18m;

        try_files $uri $uri/ /index.php?$query_string;

    }   


 location /path-to-video-upload {

        client_max_body_size 256m;

        try_files $uri $uri/ /index.php?$query_string;

    }   


您不需要匹配任何 .php 正则表达式,除非您的路由中明确包含 php。它将匹配一个完整的 Laravel 路由,并将正文大小限制仅应用于该 URL。


查看完整回答
反对 回复 2022-10-14
  • 1 回答
  • 0 关注
  • 78 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信