Laravel Nginx PHP-FPM 特定 url client_max_body_size

我在 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";

    }

}


DIEA
浏览 85回答 1
1回答

慕虎7371278

恢复到您的原始配置,只更改这些: 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。
打开App,查看更多内容
随时随地看视频慕课网APP