๐๐ป Nextjs์ค์ ํ๋ก์ ํธ ์์๊ณผ ํจ๊ป ์ฌ๋ฌ๋ถ์ ๋ก์ปฌ PC์ https์ค์ ์ ํฉ๋๋ค.
As part of the Next.js project setup, you will configure HTTPS on your local machine.
๐๐ป ์ด์ ์๋ https์ค์ ์ ์ํด์ nginx์ certbot์ ์ค์นํด์ ์ฌ์ฉํ์ต๋๋ค.
Previously, I installed and used Nginx and Certbot to set up HTTPS.
๐๐ป ์ด๋ฒ์๋ ๊ฐ๋จํ cadddy๋ก https๋ฅผ ๊ตฌํํ ์์ ์
๋๋ค.
This time, I plan to implement HTTPS using Caddy.
๐๐ป ๊ธฐ์กด ๋ฐฉ์๋ณด๋ค๋ ์ค์ ์ด ๋งค์ฐ ๊ฐํธํ๊ธฐ ๋๋ฌธ์ ์์ ํ๋ก์ ํธ๋ cadddy๋ฅผ ์ถ์ฒํฉ๋๋ค.
I recommend Caddy for small projects because it is much easier to set up than traditional methods.
๐๐ป ์ฑ๋ฅ์ด ์ค์ํ ๊ณณ์ Nginx+Certbot์ ์ฌ์ฉํ์๊ณ ๊ฐ๋จํ ํ๋ก์ ํธ๋ caddy๋ฅผ ์ฌ์ฉํ์๋ฉด๋ฉ๋๋ค.
์ฑ๋ฅ์ด ์ค์ํ ๊ณณ์ Nginx+Certbot์ ์ฌ์ฉํ์๊ณ ๊ฐ๋จํ ํ๋ก์ ํธ๋ caddy๋ฅผ ์ฌ์ฉํ์๋ฉด๋ฉ๋๋ค.
๐๐ป ๋๋ฉ์ธ์ DDNS๋ฅผ ์ฌ์ฉํฉ๋๋ค.
The domain uses DDNS.
๐ Nextjs ํ๋ก์ ํธ ์์ฑ
Create a Next.js project
npx create-next-app@latest
๐ ๋๋ฉ์ธ ํ์ฉ / Allow Domain
— next.config.ts์ ์๋์ฒ๋ผ ๋๋ฉ์ธ์ ํ์ฉํฉ๋๋ค.
Allow the domain in next.config.ts as shown below.
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
allowedDevOrigins: ['host.yourdomain.org', '*.yourdomain.org'],
};
export default nextConfig;
๐ https์ค์ / HTTPS configuration
โ๏ธ macOS
— Caddy๋ ๋ฒ์ฉ ์น์๋ฒ๋ก ngin๋ณด๋คํจ์ฌ ์ฝ๊ฒ https์ค์ ์ ํ ์ ์์ต๋๋ค.
Caddy is a general-purpose web server that makes setting up HTTPS much easier than Nginx.
— Caddy๊ฐ 80์ผ๋ก ์ ์ํ๋ฉด 3000ํฌํธ๋ก ํฌ์๋ฉ ํด์ค๋๋ค.
When Caddy receives a request on port 80, it forwards it to port 3000.
brew install caddy
— Caddy file ๋ง๋ค๊ธฐ(myapp11 ํ๋ก์ ํธ๋ด )
Create a Caddyfile (within the myapp11 project)
# ํ์ผ์ด๊ธฐ / Open File
nano Caddyfile
# ์ค์ ์์ฑ / Create Configuration
aloy-horizon.duckdns.org {
reverse_proxy localhost:3000
}
#ํ์ผ ์ ์ ํ ์ข
๋ฃ / Save file and exit (Ctrl + O,Ctrl + x)
— Caddy ์คํ / Run Caddy
caddy fmt --overwrite Caddyfile
caddy run
# background
caddy start
caddy stop
# ์ฌ๋ถํ
์์๋ ์ ์ฉํ๋ ค๋ฉด
# To apply the setting even after rebooting
brew services start caddy
brew services stop caddy
โ๏ธ Linux
— Caddy ์ค์น / Installing Caddy
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
— Caddy ์คํ / Run Caddy
#
sudo mv Caddyfile /etc/caddy/Caddyfile
sudo nano /etc/caddy/Caddyfile
host.yourdomain.org {
reverse_proxy localhost:3000
}
sudo systemctl enable --now caddy
sudo systemctl status caddy
๐ ๋ธ๋ผ์ฐ์ ์ ์ / Access Browser
