웹 서버 보안 · 6 min read · Jan 24, 2026
Nginx 웹 서버 보안을 위한 팁과 요령

Nginx는 오픈 소스, 경량, 고성능의 세계에서 가장 빠르게 성장하는 웹 서버입니다. Nginx는 Linux, Windows, Mac OS 및 Solaris 운영 체제에서 실행됩니다. NGINX는 계속해서 인기를 얻고 있으며, 이는 점점 더 많은 NGINX 배포가 보안이 필요하다는 것을 의미합니다.
이 튜토리얼에서는 인기 있는 Nginx 서버 보안 팁과 요령을 설명합니다.
요구 사항
- Ubuntu 18.04 또는 Debian 9에서 실행되는 서버.
- 서버에 루트 비밀번호가 설정되어 있어야 합니다.
Nginx 설치
먼저, 시스템에 Nginx를 설치해야 합니다. 다음 명령어를 실행하여 설치할 수 있습니다:
apt-get install nginx -yNginx가 설치되면 다음 명령어로 Nginx의 상태를 확인할 수 있습니다:
systemctl status nginx다음과 같은 출력이 표시되어야 합니다:
? nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-03-10 02:43:14 UTC; 4min 40s ago
Docs: man:nginx(8)
Process: 2271 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 2281 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2274 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2285 (nginx)
Tasks: 2 (limit: 1111)
CGroup: /system.slice/nginx.service
??2285 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
??2290 nginx: worker process
Mar 10 02:43:14 ubuntu1804 systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 10 02:43:14 ubuntu1804 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Mar 10 02:43:14 ubuntu1804 systemd[1]: Started A high performance web server and a reverse proxy server.
Nginx 업데이트
Nginx 웹 서버를 업데이트해야 합니다. 성능 향상, 새로운 기능 및 보안 수정이 추가되고 있습니다. 대부분의 최신 Linux 배포판은 기본 패키지 목록에 최신 버전의 Nginx를 포함하지 않습니다. 따라서 패키지 관리자를 통해 최신 버전의 Nginx로 업그레이드해야 합니다. 다음 명령어로 Nginx 웹 서버를 업데이트할 수 있습니다:
apt-get update -y
apt-get install nginx --reinstall -y정보 공개 방지
먼저, Nginx가 버전 정보를 공개하지 않도록 해야 합니다.
기본적으로 Nginx는 HTTP 헤더에 이름과 버전을 표시합니다.
다음 명령어로 확인할 수 있습니다:
curl -I http://localhost다음과 같은 출력이 표시되어야 합니다:
HTTP/1.1 200 OK
Server: nginx/1.14.0 (Ubuntu)
Date: Sat, 09 Mar 2019 15:28:01 GMT
Content-Type: text/html
Content-Length: 10918
Last-Modified: Fri, 01 Feb 2019 16:05:17 GMT
Connection: keep-alive
ETag: "5c546e3d-2aa6"
Accept-Ranges: bytes
위의 출력에서 Nginx 및 운영 체제 버전을 확인할 수 있습니다.
이 정보를 숨기려면 /etc/nginx/nginx.conf 파일을 편집합니다:
nano /etc/nginx/nginx.confhttp 구성 부분 안에 server_tokens off 줄을 추가합니다:
http {
##
# Basic Settings
##
server_tokens off;
작업이 끝나면 파일을 저장하고 닫습니다. 그런 다음 변경 사항을 적용하기 위해 Nginx 웹 서버를 재시작합니다:
systemctl restart nginx이제 curl 명령어를 다시 실행합니다:
curl -I http://localhost다음과 같은 출력이 표시되어야 합니다:
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 09 Mar 2019 15:33:31 GMT
Content-Type: text/html
Content-Length: 10918
Last-Modified: Fri, 01 Feb 2019 16:05:17 GMT
Connection: keep-alive
ETag: "5c546e3d-2aa6"
Accept-Ranges: bytes
접근 IP 제한
Nginx는 특정 IP 주소를 허용하거나 거부할 수 있는 ngx_http_access_module이라는 간단한 모듈을 제공합니다.
172.16.0.0/16에서 Nginx를 허용하고 다른 서브넷에서 거부하려면 /etc/nginx/sites-enabled/default 파일을 엽니다:
nano /etc/nginx/sites-enabled/default서버 블록 안에 다음과 같은 변경을 합니다:
server {
listen 80 default_server;
listen [::]:80 default_server;
allow 172.16.0.0/16;
deny all;
작업이 끝나면 파일을 저장하고 닫습니다. 그런 다음 이러한 변경 사항을 적용하기 위해 Nginx를 재시작합니다:
systemctl restart nginx이제 192.168.0.102와 같은 다른 IP 주소 범위에서 Nginx 서버에 접근해 보십시오.
다음으로, 다음 명령어로 Nginx 로그를 확인합니다:
tail -f /var/log/nginx/error.log다음과 같은 출력에서 접근이 금지되었다는 메시지를 확인할 수 있습니다:
2019/03/09 16:13:01 [error] 11589#11589: *1 access forbidden by rule, client: 192.168.0.102, server: _, request: "GET /test/ HTTP/1.1", host: "172.16.0.122"
TLS로 Nginx 보안
TLS(전송 계층 보안)는 SSL(보안 소켓 계층)의 후속 버전입니다. 더 강력하고 효율적인 HTTPS를 제공하며, 포워드 시크리시, 최신 OpenSSL 암호 모음과의 호환성 및 HSTS와 같은 여러 가지 향상을 포함합니다. 이 튜토리얼에서는 Nginx에서 자체 서명된 SSL 인증서를 활성화하는 방법을 보여줍니다. 대신 Let’s Encrypt 인증서를 사용하려면 여기를 참조하십시오: https://www.howtoforge.com/tutorial/nginx-with-letsencrypt-ciphersuite/
먼저, 다음 명령어로 SSL 디렉토리를 생성합니다:
mkdir /etc/nginx/ssl/다음으로, 다음 명령어로 키와 인증서를 생성합니다:
cd /etc/nginx/ssl/먼저, 다음 명령어로 키를 생성합니다:
openssl genrsa -aes256 -out nginx.key 1024다음과 같은 출력이 표시되어야 합니다:
Generating RSA private key, 1024 bit long modulus
...++++++
.............................++++++
e is 65537 (0x010001)
Enter pass phrase for nginx.key:
Verifying - Enter pass phrase for nginx.key:
다음으로, 다음 명령어로 csr을 생성합니다:
openssl req -new -key nginx.key -out nginx.csr아래와 같이 모든 정보를 제공하십시오:
Generating RSA private key, 1024 bit long modulus
...++++++
.............................++++++
e is 65537 (0x010001)
Enter pass phrase for nginx.key:
Verifying - Enter pass phrase for nginx.key:
root@ubuntu1804:~# openssl req -new -key nginx.key -out nginx.csr
Enter pass phrase for nginx.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:Gujarat
Locality Name (eg, city) []:Junagadh
Organization Name (eg, company) [Internet Widgits Pty Ltd]:IT
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:HITESH
Email Address []:[email protected]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:admin
An optional company name []:IT
다음으로, 다음 명령어로 인증서에 서명합니다:
openssl x509 -req -days 365 -in nginx.csr -signkey nginx.key -out nginx.crt다음과 같은 출력이 표시되어야 합니다:
Signature ok
subject=C = IN, ST = Gujarat, L = Junagadh, O = IT, OU = IT, CN = HITESH, emailAddress = [email protected]
Getting Private key
Enter pass phrase for nginx.key:
다음으로, Nginx 기본 가상 호스트 파일을 열고 인증서를 정의합니다:
nano /etc/nginx/sites-enabled/default다음과 같은 변경을 합니다:
server {
listen 192.168.0.100:443 ssl;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
작업이 끝나면 파일을 저장하고 닫습니다. 그런 다음 이러한 변경 사항을 적용하기 위해 Nginx 서버를 재시작합니다:
systemctl restart nginx디렉토리 비밀번호 보호
Nginx 웹 서버를 설정할 때 특정 디렉토리를 비밀번호로 보호할 수도 있습니다. .htpasswd 파일을 사용하여 이를 수행할 수 있습니다.
이를 위해 passwd 파일을 생성하고 다음 명령어로 사용자 추가합니다:
mkdir /etc/nginx/.htpasswd
htpasswd -c /etc/nginx/.htpasswd/passwd admin다음과 같은 출력이 표시되어야 합니다:
New password:
Re-type new password:
Adding password for user admin
다음으로, 다음 명령어로 Nginx 웹 루트 안에 테스트 디렉토리를 생성합니다:
mkdir /var/www/html/test다음으로, 다음 명령어로 www-data 사용자에게 소유권을 부여합니다:
chown -R www-data:www-data /var/www/html/test다음으로, 다음 명령어로 Nginx 기본 가상 호스트 파일을 엽니다:
nano /etc/nginx/sites-enabled/default다음으로, 아래와 같이 테스트 디렉토리를 보호합니다:
location /test {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd/passwd;
작업이 끝나면 파일을 저장하고 닫습니다. 그런 다음 이러한 변경 사항을 적용하기 위해 Nginx 서비스를 재시작합니다:
systemctl restart nginx다음으로, 웹 브라우저를 열고 URL http://your-server-ip/test를 입력합니다. 테스트 디렉토리에 접근하기 위해 사용자 이름과 비밀번호를 입력하라는 메시지가 표시됩니다:

축하합니다! Ubuntu 18.04 서버에서 Nginx 서버를 성공적으로 보안했습니다. 이 정보가 Nginx 웹 서버에 호스팅된 애플리케이션을 보호하는 데 도움이 되기를 바랍니다. 질문이 있으면 언제든지 문의해 주세요. 더 많은 정보는 Nginx 보안 문서를 참조할 수 있습니다.
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.