簡體   English   中英

Laravel Nginx PHP-FPM 特定 url client_max_body_size

[英]Laravel Nginx PHP-FPM specific 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"; } }

這是我到目前為止沒有運氣的嘗試(403請求實體太大):

 server { listen 80; listen [::]:80; root /path-to-web/public; index index.php index.html; server_name www.myweb.com; proxy_connect_timeout 180s; proxy_send_timeout 180s; proxy_read_timeout 180s; fastcgi_send_timeout 180s; fastcgi_read_timeout 180s; location / { client_max_body_size 18m; try_files $uri $uri/ /index.php?$query_string; } location ~ ^/path-to-video-upload/.+\\.php$ { client_max_body_size 256M; 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\\"upload_max_filesize=\\"256M\\"post_max_size=\\"256M\\""; } # pass the PHP scripts to FastCGI server # location ~ \\.php$ { client_max_body_size 18m; 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; proxy_connect_timeout 180s; proxy_send_timeout 180s; proxy_read_timeout 180s; fastcgi_send_timeout 180s; fastcgi_read_timeout 180s; location / { client_max_body_size 18m; try_files $uri $uri/ /index.php?$query_string; } location ~ ^/path-to-video-upload/.+\\.php$ { client_max_body_size 256M; 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\\"upload_max_filesize=\\"256M\\"post_max_size=\\"256M\\""; } # pass the PHP scripts to FastCGI server # location ~ \\.php$ { client_max_body_size 18m; 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"; } }

謝謝你的幫助。

感謝@Darryl E. Clarke 的回答,我設法讓它發揮作用。 解決方案:

 server { listen 80; listen [::]:80; root /path-to-laravel-app/public; index index.php index.html; server_name www.myweb.com; proxy_connect_timeout 180s; proxy_send_timeout 180s; proxy_read_timeout 180s; fastcgi_send_timeout 180s; fastcgi_read_timeout 180s; client_body_buffer_size 16k; location / { client_max_body_size 18M; try_files $uri $uri/ /index.php?$query_string; } location /path-to/upload-file/ { client_max_body_size 256M; try_files $uri $uri/ /index.php?$query_string; } # pass the PHP scripts to FastCGI server # location ~ \\.php$ { client_max_body_size 256M; 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\\" upload_max_filesize=\\"256M\\" post_max_size=\\"256M\\""; } } server { listen 443; listen [::]:443; ssl on; ssl_protocols TLSv1.2 TLSv1.3; ssl_certificate /path-to-cert/cert.pem; ssl_certificate_key /path-to-cert/cert.key; root /path-to-laravel-app/public; index index.php index.html; server_name www.myweb.com; proxy_connect_timeout 180s; proxy_send_timeout 180s; proxy_read_timeout 180s; fastcgi_send_timeout 180s; fastcgi_read_timeout 180s; client_body_buffer_size 16k; location / { client_max_body_size 18M; try_files $uri $uri/ /index.php?$query_string; } location /path-to/upload-file/ { client_max_body_size 256M; try_files $uri $uri/ /index.php?$query_string; } # pass the PHP scripts to FastCGI server # location ~ \\.php$ { client_max_body_size 256M; 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\\" upload_max_filesize=\\"256M\\" post_max_size=\\"256M\\""; } }

謝謝!

恢復到您的原始配置,只更改這些:

 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 應用 body 大小限制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM