๐Ÿชถ

Apache HTTP Server ์น˜ํŠธ์‹œํŠธ

apachectl/httpd ์ œ์–ด, ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ(VirtualHost), ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ(mod_proxy), URL ์žฌ์ž‘์„ฑ(mod_rewrite/.htaccess), SSL/TLS(HTTPS), ๋ณด์•ˆ ๋ฐ MPM ์„ฑ๋Šฅ ํŠœ๋‹

--views
๋‹จ์ˆ˜:
#apache#httpd#webserver#reverse-proxy#ssl#mod_rewrite#htaccess#devops์ตœ์ข… ์—…๋ฐ์ดํŠธ: 2026-09-27

1. Apache ์„ค์น˜ ๊ฐ€์ด๋“œ (Installation)

๐Ÿ’ป ์‹œ์Šคํ…œ ์„ค์น˜ ๋ฐ ์‹คํ–‰ ์š”๊ตฌ์‚ฌ์–‘ (System Requirements)

ํ•ญ๋ชฉ์ตœ์†Œ ์‚ฌ์–‘ (Minimum)๊ถŒ์žฅ ์‚ฌ์–‘ (Recommended)์ฐธ๊ณ  ๋ฐ ๋น„๊ณ 
์šด์˜์ฒด์ œ (OS)Linux (Ubuntu, Debian, RHEL, CentOS), macOS, Windows ServerUbuntu 22.04 LTS+, RHEL 9+POSIX ํ˜ธํ™˜ 64-bit OS
CPU1 ์ฝ”์–ด ์ด์ƒ (x86_64 / ARM64)2 ์ฝ”์–ด ~ 4 ์ฝ”์–ด ์ด์ƒEvent MPM ๊ตฌ๋™ ์‹œ ์ฝ”์–ด๋‹น ์ˆ˜์ฒœ ๋™์‹œ ์ ‘์† ์ฒ˜๋ฆฌ
๋ฉ”๋ชจ๋ฆฌ (RAM)512 MB ์ด์ƒ2 GB ~ 4 GB ์ด์ƒํŠธ๋ž˜ํ”ฝ ๋ฐ KeepAlive ์ปค๋„ฅ์…˜ ์ˆ˜์— ๋”ฐ๋ผ ์ฆ์„ค
๋””์Šคํฌ (Storage)200 MB ์ด์ƒ์˜ ์—ฌ์œ  ๊ณต๊ฐ„5 GB ~ 20 GB ์ด์ƒ (SSD ๊ถŒ์žฅ)์•ก์„ธ์Šค/์—๋Ÿฌ ๋กœ๊ทธ ๋ฐ ์›น ์ •์  ์ฝ˜ํ…์ธ  ์šฉ๋Ÿ‰ ๊ณ ๋ ค
๋„คํŠธ์›Œํฌ / ๋Ÿฐํƒ€์ž„๊ธฐ๋ณธ ํฌํŠธ 80(HTTP), 443(HTTPS)OpenSSL 1.1.1+, APR(Apache Portable Runtime)๋ฐฉํ™”๋ฒฝ ์ธ๋ฐ”์šด๋“œ ํฌํŠธ ๊ฐœ๋ฐฉ ํ•„์ˆ˜
# ๐Ÿง [1] Ubuntu / Debian (ํŒจํ‚ค์ง€๋ช…: apache2)
sudo apt update
sudo apt install -y apache2
sudo systemctl enable --now apache2

# ๐Ÿง [2] RHEL / CentOS / Rocky Linux (ํŒจํ‚ค์ง€๋ช…: httpd)
sudo dnf install -y httpd
sudo systemctl enable --now httpd

# ๐Ÿณ [3] Docker ๋น ๋ฅธ ์‹คํ–‰
docker run -d --name my-apache -p 80:80 -v /my/site:/usr/local/apache2/htdocs/ httpd:alpine

# ๐Ÿ [4] macOS (Homebrew)
brew install httpd
brew services start httpd

2. CLI ์„œ๋น„์Šค ์ œ์–ด & ๋ฌธ๋ฒ• ๊ฒ€์‚ฌ (Service Control & CLI)

# ๐Ÿชถ [1] ์„ค์ • ํŒŒ์ผ ๋ฌธ๋ฒ• ๊ฒ€์‚ฌ (Syntax Check - ์„ค์ • ๋ณ€๊ฒฝ ํ›„ ํ•„์ˆ˜!)
apachectl configtest       # ๋˜๋Š” httpd -t
# ๊ตฌ์ฒด์ ์ธ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ(VirtualHost) ๋ฐ”์ธ๋”ฉ ๋ชฉ๋ก ํ™•์ธ
apachectl -S               # ๋˜๋Š” httpd -S

# ๐Ÿ”„ [2] ๋ฌด์ค‘๋‹จ ์•ˆ์ „ ๋ฆฌ๋กœ๋“œ (Graceful Reload) vs ์žฌ์‹œ์ž‘
apachectl graceful         # ์ฒ˜๋ฆฌ ์ค‘์ธ ์š”์ฒญ ์™„๋ฃŒ ํ›„ ์•ˆ์ „ํ•˜๊ฒŒ ์„ค์ • ๋ฆฌ๋กœ๋“œ (๊ถŒ์žฅ)
apachectl restart          # ์ฆ‰์‹œ ์ค‘์ง€ ํ›„ ์žฌ์‹œ์ž‘
apachectl stop             # Apache ์ค‘์ง€

# ๐Ÿง [3] systemd ์„œ๋น„์Šค ๊ด€๋ฆฌ (Linux)
# Ubuntu / Debian
sudo systemctl status apache2
sudo systemctl reload apache2
sudo systemctl restart apache2

# RHEL / CentOS / Rocky
sudo systemctl status httpd
sudo systemctl reload httpd
sudo systemctl restart httpd

# ๐Ÿ“ฆ [4] ํ™œ์„ฑํ™”๋œ ๋ชจ๋“ˆ ๋ฐ ๋ฒ„์ „ ํ™•์ธ
apachectl -M               # ๋˜๋Š” httpd -M (๋กœ๋“œ๋œ ์ „์ฒด ๋ชจ๋“ˆ ๋ชฉ๋ก)
apachectl -V               # ์ƒ์„ธ ๋นŒ๋“œ ์ •๋ณด ๋ฐ MPM ๋ชจ๋“œ ํ™•์ธ

3. ๋ฐฐํฌํŒ๋ณ„ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ & ๋ชจ๋“ˆ ํ™œ์„ฑํ™”

๊ตฌ๋ถ„Ubuntu / Debian (apache2)RHEL / CentOS (httpd)
๋ฉ”์ธ ์„ค์ • ํŒŒ์ผ/etc/apache2/apache2.conf/etc/httpd/conf/httpd.conf
ํฌํŠธ ์„ค์ •/etc/apache2/ports.conf๋ฉ”์ธ ์„ค์ • ๋‚ด Listen 80
๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ/etc/apache2/sites-available//etc/httpd/conf.d/*.conf
๋ชจ๋“ˆ ๋””๋ ‰ํ† ๋ฆฌ/etc/apache2/mods-available//etc/httpd/conf.modules.d/
๊ธฐ๋ณธ DocumentRoot/var/www/html/var/www/html
๊ธฐ๋ณธ ๋กœ๊ทธ ๊ฒฝ๋กœ/var/log/apache2//var/log/httpd/
# Ubuntu/Debian ์ „์šฉ ๋ชจ๋“ˆ ๋ฐ ์‚ฌ์ดํŠธ ํ™œ์„ฑํ™” CLI
sudo a2enmod rewrite ssl proxy proxy_http headers deflate # ๋ชจ๋“ˆ ํ™œ์„ฑํ™”
sudo a2dismod autoindex                                   # ๋ชจ๋“ˆ ๋น„ํ™œ์„ฑํ™”
sudo a2ensite my-site.conf                                # ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ํ™œ์„ฑํ™”
sudo a2dissite 000-default.conf                           # ๊ธฐ๋ณธ ์‚ฌ์ดํŠธ ๋น„ํ™œ์„ฑํ™”

4. ๊ธฐ๋ณธ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ (VirtualHost: ํฌํŠธ 80)

# /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin admin@example.com
    DocumentRoot /var/www/example.com/public_html

    # ๋””๋ ‰ํ† ๋ฆฌ๋ณ„ ์ ‘๊ทผ ๊ถŒํ•œ ์„ค์ •
    <Directory /var/www/example.com/public_html>
        Options -Indexes +FollowSymLinks # -Indexes: ํŒŒ์ผ ๋ชฉ๋ก ๋…ธ์ถœ ์ฐจ๋‹จ
        AllowOverride All                # .htaccess ํŒŒ์ผ ์‚ฌ์šฉ ํ—ˆ์šฉ (None: ๋ฌด์‹œ)
        Require all granted              # ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ ์ ‘๊ทผ ํ—ˆ๊ฐ€
    </Directory>

    # ์—๋Ÿฌ ๋ฐ ์•ก์„ธ์Šค ๋กœ๊ทธ ๊ฒฝ๋กœ
    ErrorLog ${APACHE_LOG_DIR}/example_error.log
    CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>

5. ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ (Reverse Proxy & Load Balancer)

Spring Boot, Node.js, Tomcat ๋“ฑ์œผ๋กœ ํŠธ๋ž˜ํ”ฝ์„ ํ”„๋ก์‹œ ์ „๋‹ฌํ•  ๋•Œ ์‚ฌ์šฉ (mod_proxy, mod_proxy_http ํ•„์š”).

<VirtualHost *:80>
    ServerName api.example.com

    # ํ”„๋ก์‹œ ์„ค์ •
    ProxyRequests Off               # Forward Proxy ๋น„ํ™œ์„ฑํ™” (๋ณด์•ˆ ํ•„์ˆ˜)
    ProxyPreserveHost On            # ์›๋ณธ ์š”์ฒญ์˜ Host ํ—ค๋”๋ฅผ ๋ฐฑ์—”๋“œ๋กœ ๋ณด์กด ์ „๋‹ฌ
    ProxyAddHeaders On              # X-Forwarded-For, X-Forwarded-Host ์ž๋™ ์ถ”๊ฐ€

    # [1] ๋‹จ์ผ ๋ฐฑ์—”๋“œ ํ”„๋ก์‹œ (ํฌํŠธ 8080)
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    # [2] ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ (Round Robin)
    <Proxy "balancer://mycluster">
        BalancerMember http://192.168.1.11:8080 route=node1
        BalancerMember http://192.168.1.12:8080 route=node2
        ProxySet lbmethod=byrequests
    </Proxy>
    # ProxyPass / balancer://mycluster/
    # ProxyPassReverse / balancer://mycluster/
</VirtualHost>

6. URL ์žฌ์ž‘์„ฑ (mod_rewrite) & .htaccess

SPA(Vue/React) ๋ผ์šฐํŒ… ๋ฐ 301 ์˜๊ตฌ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํŒจํ„ด (RewriteEngine On ํ•„์ˆ˜).

# [1] HTTP -> HTTPS ๋ฌด์กฐ๊ฑด ์˜๊ตฌ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ (301)
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# [2] WWW ์—†๋Š” ๋„๋ฉ”์ธ์œผ๋กœ ํ†ตํ•ฉ (example.com)
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

# [3] Vue / React / Angular SPA ๋ผ์šฐํŒ… (HTML5 History Mode Fallback)
<Directory /var/www/spa/dist>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f # ์‹ค์ œ ํŒŒ์ผ์ด ์•„๋‹ˆ๋ฉด
    RewriteCond %{REQUEST_FILENAME} !-d # ์‹ค์ œ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์•„๋‹ˆ๋ฉด
    RewriteRule . /index.html [L]       # index.html๋กœ ๋‚ด๋ถ€ ํฌ์›Œ๋”ฉ
</Directory>
  • [NC]: No Case (๋Œ€์†Œ๋ฌธ์ž ๋ฌด์‹œ)
  • [L]: Last (์ด ๊ทœ์น™์ด ๋งค์นญ๋˜๋ฉด ๋‹ค์Œ Rewrite ๊ทœ์น™ ๊ฑด๋„ˆ๋œ€)
  • [R=301]: HTTP 301 ์˜๊ตฌ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ (๊ฒ€์ƒ‰์—”์ง„ SEO ์ตœ์ ํ™”)

7. SSL/TLS (HTTPS: ํฌํŠธ 443) ๋ณด์•ˆ ์„ค์ •

<VirtualHost *:443>
    ServerName example.com
    DocumentRoot /var/www/example.com/public_html

    # SSL ํ™œ์„ฑํ™” ๋ฐ ์ธ์ฆ์„œ ๊ฒฝ๋กœ (Let's Encrypt ํ‘œ์ค€ ์˜ˆ์‹œ)
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

    # ๋ชจ๋˜ ๋ณด์•ˆ ํ”„๋กœํ† ์ฝœ ๋ฐ ์•”ํ˜ธํ™” ์Šค์œ„ํŠธ (TLS 1.2, 1.3๋งŒ ํ—ˆ์šฉ)
    SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
    SSLCipherSuite HIGH:!aNULL:!MD5:!3DES
    SSLHonorCipherOrder on

    # HSTS ํ™œ์„ฑํ™” (๋ธŒ๋ผ์šฐ์ €์— HTTPS ์ ‘์† ๊ฐ•์ œ, 6๊ฐœ์›”)
    Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</VirtualHost>

8. ๋ณด์•ˆ ๊ฐ•ํ™”, Gzip ์••์ถ• & ๋ธŒ๋ผ์šฐ์ € ์บ์‹ฑ

# ๐Ÿ”’ [1] ์„œ๋ฒ„ ๋ฒ„์ „ ์ •๋ณด ์€๋‹‰ (๋ณด์•ˆ ํ•„์ˆ˜)
ServerTokens Prod       # Server ํ—ค๋”์— 'Apache'๋งŒ ๋…ธ์ถœ (OS ๋ฐ ์„ธ๋ถ€๋ฒ„์ „ ์ˆจ๊น€)
ServerSignature Off     # ์—๋Ÿฌ ํŽ˜์ด์ง€ ํ•˜๋‹จ ์„œ๋ฒ„ ์ •๋ณด ์ถœ๋ ฅ ๋น„ํ™œ์„ฑํ™”

# ๐Ÿ›ก๏ธ [2] ํ•„์ˆ˜ ๋ณด์•ˆ ์‘๋‹ต ํ—ค๋” ์ถ”๊ฐ€ (mod_headers)
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"

# ๐Ÿ—œ๏ธ [3] Gzip ํ…์ŠคํŠธ ์••์ถ• ์ „์†ก (mod_deflate)
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    AddOutputFilterByType DEFLATE application/javascript application/json application/xml
</IfModule>

# โšก [4] ๋ธŒ๋ผ์šฐ์ € ์บ์‹ฑ ๋งŒ๋ฃŒ ์‹œ๊ฐ„ ์„ค์ • (mod_expires)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png  "access plus 1 month"
    ExpiresByType text/css   "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>

9. MPM ๋ชจ๋“œ & ์„ฑ๋Šฅ ์ตœ์ ํ™” (Event MPM ๊ถŒ์žฅ)

Apache 2.4+ ํ™˜๊ฒฝ์—์„œ๋Š” ๊ณ ์„ฑ๋Šฅ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•œ mpm_event๊ฐ€ ๊ธฐ๋ณธ ๊ถŒ์žฅ๋ฉ๋‹ˆ๋‹ค.

# /etc/apache2/mods-available/mpm_event.conf
<IfModule mpm_event_module>
    StartServers             3      # ์ดˆ๊ธฐ ๊ธฐ๋™ํ•  ํ”„๋กœ์„ธ์Šค ์ˆ˜
    MinSpareThreads         75      # ์ตœ์†Œ ์œ ํœด ์Šค๋ ˆ๋“œ ์ˆ˜
    MaxSpareThreads        250      # ์ตœ๋Œ€ ์œ ํœด ์Šค๋ ˆ๋“œ ์ˆ˜
    ThreadsPerChild         25      # ์ž์‹ ํ”„๋กœ์„ธ์Šค๋‹น ์ƒ์„ฑํ•  ์Šค๋ ˆ๋“œ ์ˆ˜
    MaxRequestWorkers      400      # ๋™์‹œ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅํ•œ ์ตœ๋Œ€ ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ ์ˆ˜
    MaxConnectionsPerChild   0      # ํ”„๋กœ์„ธ์Šค ์žฌ์‚ฌ์šฉ ํšŸ์ˆ˜ (0: ๋ฌด์ œํ•œ)
</IfModule>

# KeepAlive ์ปค๋„ฅ์…˜ ์žฌ์‚ฌ์šฉ ์„ค์ •
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5                  # ์œ ํœด ์—ฐ๊ฒฐ ์œ ์ง€ ์‹œ๊ฐ„ (์ดˆ ๋‹จ์œ„)

10. ์‹ค๋ฌด ํ”„๋ก์‹œ + HTTPS ์ข…ํ•ฉ ๊ฐ€์ƒํ˜ธ์ŠคํŠธ ์˜ˆ์ œ

# /etc/apache2/sites-available/api-ssl.conf
<VirtualHost *:443>
    ServerName api.luckytechworld.com
    ServerAdmin admin@luckytechworld.com

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/api.luckytechworld.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/api.luckytechworld.com/privkey.pem

    # Spring Boot / Node.js ๋ฐฑ์—”๋“œ๋กœ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    # ๋กœ๊ทธ ์„ค์ •
    ErrorLog ${APACHE_LOG_DIR}/api_error.log
    CustomLog ${APACHE_LOG_DIR}/api_access.log combined
</VirtualHost>
๐Ÿ’ฌ

์˜๊ฒฌ ๋ฐ ์งˆ๋ฌธ

0
0 / 1500