๐๐ป ๋ฆฌ๋
์ค์๋ฒ์์ ํ
์คํธ ํ ๋ด์ฉ์
๋๋ค.
This is the content tested on a Linux server.
๐๐ป Let’s Encrypt๋ก https๋ฅผ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์
๋๋ค.
This is how to implement HTTPS with Let’s Encrypt.
๐๐ป ๋ฐฉํ๋ฒฝ์คํ / Firewall open
— ์๋๋ iptables ๋ฐฉํ๋ฒฝ ์คํ ํ๋ ๋ด์ฉ์
๋๋ค.
Below is the content for opening the iptables firewall.
$ sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
$ sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
$ sudo iptables -I INPUT -p tcp --dport 5080 -j ACCEPT
# iptables-persistent์ค์น์ํ๊ฒฝ์ฐ
$ sudo apt install iptables-persistent
# ์ค์ ๋ด์ฉ์ ์ฅ / Save settings
$ sudo netfilter-persistent save
๐๐ป openssl์ด์ค์น๋์ด ์์ง ์์ผ๋ฉด ์ค์นํฉ๋๋ค.
If openssl is not installed, install it.
sudo apt update
sudo apt install g++ libssl-dev openssl wget -y
โญ๏ธ openssl์ 3.0์ด์์ ์ฌ์ฉํด์ผํฉ๋๋ค.
You must use openssl 3.0 or higher.
โญ๏ธ openssl 3.x์ด์์ ์ฌ์ฉํ๋ ค๋ฉด ์ฐ๋ถํฌ 22.04๋ฒ์ ์ด์์ด์ด์ผํฉ๋๋ค.
To use openssl 3.x or higher, you must be running Ubuntu version 22.04 or higher.
๐๐ป Let’s Encrypt์ธ์ฆ์ ๋ฐ๊ธฐ / Get Let’s Encrypt Certificate
— ๋ค์๊ณผ ๊ฐ์ ํ๋ฉด์ด ๋ณด์ด๋ฉด ์ฑ๊ณตํ ๊ฒ์
๋๋ค.
If you see the following screen, you have succeeded.
–๋ฐฉํ๋ฒฝ์ด๋ ํฌํธ๊ฐ ๋งํ๋ฉด ์ธ์ฆ์ ๋ฐ๊ธ์ด ๋์ง ์์ต๋๋ค.
If the firewall or ports are blocked, the certificate cannot be issued.
$ sudo certbot certonly --standalone -d host.domain.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for host.domain.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/host.domain.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/host.domain.com/privkey.pem
This certificate expires on 2028-10-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$
๐๐ป ํ์ฌ ์๋ฒ ๋๋ ํ ๋ฆฌ๋ก ์ธ์ฆ์๋ฅผ ๋ณต์ฌํฉ๋๋ค.
Copy certificate to current server directory
$ sudo cp /etc/letsencrypt/live/host.domain.com/fullchain.pem ./
$ sudo cp /etc/letsencrypt/live/host.domain.com/privkey.pem ./
# ๋ด ๊ณ์ ์ผ๋ก ์์ ๊ถ ๋ณ๊ฒฝ / Change ownership to my account
$ sudo chown username:username *.pem
๐๐ป ์ฝ๋/Code
โ๏ธ ๊ธฐ์กด์ ์๋ฒ ์ฝ๋์์ ์ธ์ฆ์ ๋ถ๋ถ๋ง ์์ ํฉ๋๋ค.
Modify only the certificate part of the existing server code.
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "httplib.h"
#include <iostream>
int main( ) {
// ์ธ์ฆ์์ ํค ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ง์ ํฉ๋๋ค.
// Specify the certificate and key file paths.
httplib::SSLServer svr("./fullchain.pem", "./privkey.pem" );
if (!svr.is_valid()) {
std::cerr << "SSL ์๋ฒ ์ค์ ์คํจ / SSL server setup failed!" << std::endl;
return 1;
}
svr.Get("/", [](const httplib::Request&, httplib::Response& res ) {
res.set_content("<h1> ๐ Linux HTTPS Server is Running! ๐ </h1>", "text/html; charset=utf-8");
});
std::cout << "Server Listening: https://0.0.0.0:5080" << std::endl;
svr.listen("0.0.0.0", 5080 );
return 0;
}
๐๐ป ์ปดํ์ผ / Compiling
g++ -o server server.cpp -std=c++11 -pthread -lssl -lcrypto
๐๐ป ์๋ฒ์คํ / Run server
./server
๐๐ป ๋ธ๋ผ์ฐ์ ์ ์ / Browser access
