nginx 설정 · 4 min read · Jan 23, 2026
Debian에서 nginx로 업로드 진행률 표시하기
Debian에서 nginx로 업로드 진행률 표시하기
이 튜토리얼은 nginx 업로드 진행률 모듈을 사용하여 하나 이상의 파일을 업로드하고 사용자에게 업로드 진행률 표시줄을 표시하는 방법을 보여줍니다. 이는 사용자가 대용량 파일을 업로드할 때, 백그라운드에서 무언가 진행되고 있다는 것을 알 수 있도록 유용합니다.
이것이 당신에게 작동할 것이라는 보장은 하지 않습니다!
1 nginx-extras 설치하기
nginx 업로드 진행률 모듈은 기본적으로 활성화되어 있지 않습니다. 다음 명령어를 실행하여 활성화되어 있는지 확인할 수 있습니다:
nginx -V출력에서 –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-upload-progress와 같은 내용을 확인할 수 있어야 합니다. 활성화되어 있지 않다면, nginx-extras 패키지를 설치하세요:
apt-get install nginx-extras그 후 다시 실행하세요:
nginx -V업로드 진행률 모듈이 이제 출력에 나타나야 합니다:
root@server1:/var/www# nginx -V
nginx version: nginx/1.4.4
TLS SNI support enabled
configure arguments: –prefix=/usr/share/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-client-body-temp-path=/var/lib/nginx/body –http-fastcgi-temp-path=/var/lib/nginx/fastcgi –http-log-path=/var/log/nginx/access.log –http-proxy-temp-path=/var/lib/nginx/proxy –http-scgi-temp-path=/var/lib/nginx/scgi –http-uwsgi-temp-path=/var/lib/nginx/uwsgi –lock-path=/var/lock/nginx.lock –pid-path=/run/nginx.pid –with-pcre-jit –with-debug –with-http_addition_module –with-http_dav_module –with-http_flv_module –with-http_geoip_module –with-http_gzip_static_module –with-http_image_filter_module –with-http_mp4_module –with-http_perl_module –with-http_random_index_module –with-http_realip_module –with-http_secure_link_module –with-http_spdy_module –with-http_stub_status_module –with-http_ssl_module –with-http_sub_module –with-http_xslt_module –with-ipv6 –with-mail –with-mail_ssl_module –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/headers-more-nginx-module –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-auth-pam –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-cache-purge –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-dav-ext-module –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-development-kit –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-echo –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/ngx-fancyindex –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-http-push –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-lua –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-upload-progress –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/nginx-upstream-fair –add-module=/tmp/buildd/nginx-1.4.4/debian/modules/ngx_http_substitutions_filter_module
root@server1:/var/www#
모듈을 활성화하려면, 업로드를 추적하는 데 사용되는 작은 영역을 nginx.conf (http {} 컨테이너 내)에 생성해야 합니다 (이 예제에서는 영역 이름을 uploads로 지정합니다):
vi /etc/nginx/nginx.conf| [...] http { [...] # 업로드를 추적하기 위해 'uploads'라는 이름 아래 1MB를 예약합니다. upload_progress uploads 1m; [...] } [...] |
그 후 nginx를 다시 로드하세요:
/etc/init.d/nginx reload2 Vhost 구성하기
이제 vhost 구성 파일을 열고 server {} 컨테이너 내에 다음 내용을 넣으세요 (ISPConfig를 사용하는 경우, 웹사이트의 nginx 지시어 필드에 넣으세요):
| [...] client_max_body_size 100M; location = /upload.php { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/lib/php5-fpm/web1.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; ## 위에서 정의한 영역에서 이 위치의 업로드를 추적합니다. ## 60초 타임아웃. track_uploads uploads 60s; } location ^~ /progress { upload_progress_json_output; report_uploads uploads; } [...] |
내 경우 업로드를 처리하는 파일(즉, HTML 업로드 양식의 action 속성에 있는 파일)은 upload.php라고 하며 문서 루트에 위치합니다. 파일 이름이 다르다면 location = /upload.php {를 적절히 조정하세요. 또한 웹사이트에 맞는 fastcgi_pass 옵션을 사용하고 있는지 확인하세요 (여기서 사용하는 소켓과는 다른 소켓을 사용할 가능성이 높거나, 소켓 대신 TCP 연결을 사용하고 있을 수 있습니다).
track_uploads 줄에서는 1장에서 사용한 upload_progress 영역의 이름을 사용하는 것이 중요합니다 (이 경우 uploads).
location ^~ /progress {} 컨테이너는 문자 그대로 받아들여야 하며, 변경하지 마세요 (업로드 진행률 영역의 이름이 uploads가 아니라면 report_uploads 줄을 변경해야 합니다). 이 위치는 nginx에 파일 업로드 상태를 요청하는 데 사용됩니다.
그 후 nginx를 다시 로드하세요 (ISPConfig를 사용하는 경우, ISPConfig가 자동으로 로드합니다):
/etc/init.d/nginx reload3 업로드 양식 만들기
다음으로 업로드 중에 진행률 위치를 폴링하는 JavaScript가 포함된 업로드 양식이 필요합니다. 내 파일은 다음과 같으며, index.html, upload.html 등으로 이름을 지정하고 문서 루트에 넣으세요:
| |
다음으로 upload.php를 문서 루트에 넣으세요:
| "; } } ?> |
upload.php는 업로드된 파일을 cache라는 디렉토리에 저장하므로, 문서 루트에 해당 디렉토리를 생성하고 PHP가 쓸 수 있도록 적절한 권한을 부여하는 것을 잊지 마세요.
그게 전부입니다. 이제 브라우저에서 업로드 양식이 있는 파일을 호출하고 파일을 업로드해 보세요:

4 링크
- nginx 업로드 진행률 모듈: http://wiki.nginx.org/HttpUploadProgressModule
- nginx: http://nginx.org
- Debian: http://www.debian.org
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.