본문 바로가기

리눅스

[리눅스] NGINX 및 PHP에서 파일 업로드 크기 제한을 변경하는 방법

728x90

NGINX 및 PHP에서 파일 업로드 크기 제한을 변경하는 방법

1. NGINX에서 파일 업로드 크기 제한 변경

NGINX에서 파일 업로드 크기 제한을 변경하려면 다음과 같은 단계를 따릅니다.

1-1. NGINX 구성 파일을 엽니다. 일반적으로 /etc/nginx/nginx.conf 파일입니다.

1-2. http 블록 안에 다음 라인을 추가합니다.

vim /etc/nginx/nginx.conf
client_max_body_size 20M;

 이 예에서는 20MB를 최대 파일 업로드 크기로 설정했습니다.

1-3. 구성 파일을 저장하고 NGINX를 다시 로드합니다.

sudo service nginx reload

2. PHP에서 파일 업로드 크기 제한 변경

PHP에서 파일 업로드 크기 제한을 변경하려면 다음과 같은 단계를 따릅니다.

2-1. PHP 구성 파일을 엽니다. 일반적으로 /etc/php/php.ini 파일입니다.

2-2. upload_max_filesize 및 post_max_size 디렉티브 값을 변경합니다. 예를 들어, 다음과 같이 값을 변경할 수 있습니다.

vim /etc/php/php.ini
upload_max_filesize = 20M
post_max_size = 20M

2-3. 구성 파일을 저장하고 PHP를 다시 시작합니다.

sudo service php-fpm restart

이제 NGINX 및 PHP에서 파일 업로드 크기 제한이 변경되었습니다.

 


nginx.conf 설정

vim /etc/nginx/nginx.conf
$ vim /etc/nginx/nginx.conf
...
client_max_body_size 64M;
client_body_timeout 60s;

https://runebook.dev/ko/docs/nginx/http/ngx_http_core_module
http://nginx.org/en/docs/http/ngx_http_core_module.html

php.ini 설정

vim /etc/php.ini
$ vim /etc/php.ini
max_execution_time = 300
max_input_time = 60
memory_limit = 256M
post_max_size = 64M
file_uploads = On
upload_max_filesize = 64M
max_file_uploads = 20

Maximum execution time of each script, in seconds
max_execution_time = 300

Maximum amount of time each script may spend parsing request data.

It's a good idea to limit this time on productions servers in order to eliminate unexpectedly long running scripts.
 ; Note: This directive is hardcoded to -1 for the CLI SAPI
 ; Default Value: -1 (Unlimited)
 ; Development Value: 60 (60 seconds)
 ; Production Value: 60 (60 seconds)
max_input_time = 60

Maximum amount of memory a script may consume (128MB)
memory_limit = 256M

Maximum size of POST data that PHP will accept.

Its value may be 0 to disable the limit. It is ignored if POST data reading is disabled through enable_post_data_reading.
post_max_size = 64M

Whether to allow HTTP file uploads.
file_uploads = On

Maximum allowed size for uploaded files.
upload_max_filesize = 64M

Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

 

728x90