๋ณธ๋ฌธ์œผ๋กœ ๋ฐ”๋กœ๊ฐ€๊ธฐ

 

1. NGINX as a Reverse Proxy

root๊ถŒํ•œ์œผ๋กœ application์„ ์‹คํ–‰ํ•˜๋Š” ๊ฑด ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค.

NGNIX๋ฅผ ์ด์šฉํ•ด ํ”„๋ก์‹œ ์„œ๋ฒ„๋ฅผ ๋‘์ž.

# default๋กœ ์„ค์น˜ ๋œ apache2 ์ œ๊ฑฐ

sudo apt remove apache2
sudo apt purge apache2
sudo apt install nginx
# ํฌํŠธ ํ—ˆ์šฉ
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https

# ๋ฐฉํ™”๋ฒฝ ํ™œ์„ฑํ™”
sudo ufw enable
sudo ufw status

 

2. NGINX ์„ค์ • ํŒŒ์ผ ๋ณ€๊ฒฝ

sudo vi /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
sudo vi /etc/nginx/sites-available/default
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
	    # ํฌํŠธ ํฌ์›Œ๋”ฉ ์„ค์ •
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
sudo systemctl restart nginx

 

 

 

Nginx ์ฝ”๋“œ

# ์„ค์ • ํŒŒ์ผ์„ ๊ฒ€์‚ฌํ•˜์—ฌ ๊ตฌ๋ฌธ ์˜ค๋ฅ˜๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ
sudo nginx -t

 

# nginx์˜ error.log ํŒŒ์ผ์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ชจ๋‹ˆํ„ฐ๋ง
tail -f /var/log/nginx/error.log

 

 

3. LetsEncrypt ์ ์šฉ

sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

# 90์ผ ๋ฐ–์— ์•ˆ๋˜๋‹ˆ ์ž๋™ ์žฌ์ƒ์„ฑ ์ฝ”๋“œ
sudo certbot renew

https๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ์ฝ”๋“œ๋ธ”๋Ÿญ ๊ต์ฒด

server {
    listen 80;
    listen [::]:80;
    server_name wiseprint.cloud www.wiseprint.cloud;
    return 301 https://$host$request_uri;
}

 

๋ฐ˜์‘ํ˜•