티스토리 뷰
DEPRECATED! 해당 글은 아래 링크에 더 깔끔하게 정리해놨습니다.
https://nuggy875.tistory.com/183
Nginx 초기 설정 https
서버에 https 설정하기 위해 이것저것 하라는게 많은데, 여러번 설치 해보면서 깔끔하게 필요한것만 정리해놨음. Nginx 를 통해 진행한다. // Nginx 설치 $ sudo apt-get install nginx /etc/nginx/nginx.conf 위 경
nuggy875.tistory.com
- Ubuntu 18.04 LTS 에서 진행
- Ubuntu 20.04 에서 실행 시에도 문제 없었음.
- 보유 DNS가 있어야 진행할 수 있음.
greenlock 방식이 불안하다는 얘기가 많아서
리버스 프록시 방식의 Nginx를 사용하여 https 인증을 받고 서버를 구축해보려 함
Nginx 설치
$ sudo apt-get install nginx
// 루트 전환
$ sudo su
// nginx 설정파일은 아래 경로에
$ vim /etc/nginx/nginx.conf
let's encrypt
$ wget https://dl.eff.org/certbot-auto
$ chmod a+x certbot-auto
아래와 같은 에러가 뜬다면...

1. certbot-auto의 설치 경로를 바꿔보자 (유저권환문제)
community.letsencrypt.org/t/certbot-auto-deployment-best-practices/91979
/usr/local/bin
sudo chown root /path/to/certbot-auto
2. 그래도 안되면 아래 사이트가 하라는 대로 해보자... (snapd 사용)
certbot.eff.org/lets-encrypt/ubuntubionic-nginx
하라는거 다 하고
(하라는거 예시 in ubuntu 20.04)
snapcraft.io/docs/installing-snap-on-ubuntu
$ sudo apt update $ sudo apt install snapd
$ sudo snap install hello-world
hello-world 6.4 from Canonical✓ installed $ hello-world Hello World!
$ sudo certbot --nginx
혹은
$ sudo certbot --nginx -d 사이트명
위 명령어 입력 시 인증서 발급을 진행한다.
let's encrypt & certbot
sudo apt-get install letsencrypt
(22.03.10)
위 사이트가 닫혔다. 아래 명령어로 설치
$ sudo apt update
$ sudo apt install snapd
$ sudo snap install hello-world
$ sudo snap install --classic certbot
• 인증서 발급 진행
$ sudo certbot --nginx
or
$ sudo certbot --nginx -d [적용할 사이트 이름]
ERROR
Certbot failed to authenticate some domains (authenticator: nginx). ~~~~
위와 같은 에러가 뜬다면, 방화벽을 체크하거나 80번 포트가 열려있는지 확인해보자
The requested nginx plugin does not appear to be installed
sudo apt install python-certbot-nginx
혹은
sudo apt install python3-certbot-nginx
로 해결
# nginx가 실행되고 있지 않다면 nginx 시작 (80, 443 포트를 비워놔야 함)
$ sudo systemctl start nginx
인증서 발급 완료 시 shell 에 congratulations! 하면서 나오는
fullchain.pem 과 privkey.pem 의 경로를 기억해두자.
갱신
인증서 기간은 3개월, 기간이 만료되기 전에 "certbot renew"를 해줘야함
· 먼저 잘 되는지 시뮬레이션을 해보자
$ sudo certbot renew --dry-run
가짜로 갱신을 테스트 해보는거라고 생각하면 됨
· 실제로 수동으로 인증서 갱신을 시도하기 위해선 아래 명령어 사용
$ sudo certbot renew
· 인증서 만료 날짜 등의 정보를 알고 싶다면
$ sudo certbot certificates
인증서 갱신은 명령어 한줄이면 되지만, 까먹을 수도 있고 귀찮기 때문에,
이를 자동화 하기 위해 'crontab'을 사용하면 된다
https://nuggy875.tistory.com/133
https 인증서 자동 갱신 (Let's Encrypt) (Crontab사용)
https 인증서 발급 및 수동 갱신 방법 https://nuggy875.tistory.com/119 Nginx로 https 적용하기 (let's encrypt 사용) - Ubuntu 18.04 LTS 에서 진행 - Ubuntu 20.04 에서 실행 시에도 문제 없었음. - 보유 DNS..
nuggy875.tistory.com
HTTPS 설정
다시 nginx conf 파일로 들어가서 https 설정을 만져주자
$ vim /etc/nginx/nginx.conf
혹은
$ vim /etc/nginx/sites-enabled/default
http{ ... } 부분 내에 맨 마지막 부분에 아래와 같이 입력
certbot-auto 사용 시 sites-enabled/default 내용이 자동 작성 되는데,
필자는 이에 오류를 좀 맛봐서,, 모두 주석처리하고
nginx.conf에 모두 작성해주었다. (어차피 nginx.conf가 sites-enabled를 불러옴)
# 443으로 들어가면 3030으로 보내주는 형태,
dns 두개에 대한 인증서를 발급하고,
각 dns를 다른 포트로 진행하는 예시로 해보자
/etc/nginx/ngix.conf
server {
server_name example1.com;
location / {
proxy_set_header HOST $host;
proxy_pass http://127.0.0.3030;
proxy_redirect off;
}
listen 443 ssl;
ssl_certificate [아까 받았던 fullchain.pem 경로1];
ssl_certificate_key [아까 받았던 privkey.pem 경로1];
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
server_name example2.com;
location / {
proxy_set_header HOST $host;
proxy_pass http://127.0.0.1:3080;
proxy_redirect off;
}
listen 443 ssl;
ssl_certificate [아까 받았던 fullchain.pem 경로2];
ssl_certificate_key [아까 받았던 privkey.pem 경로2];
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
# 80포트로 들어와도 443으로 꺾어줘야 돼
server {
server_name example1.com example2.com;
listen 80;
return 301 https://$host$request_uri;
}
Nginx 재시작!
$ sudo systemctl restart nginx
$ sudo service nginx reload
$ sudo /etc/init.d/nginx restart
# nginx에 문제는 없는지
$ nginx -t
Nginx 제거 후 재설치
Nginx 파일을 건들이는 중 /etc/nginx를 지워버렸는데,
apt-get remove nginx를 하고 apt-get install nginx를 해봐도 파일이 생성되지 않아 당황스러웠다...
확실히 삭제해줘야 다시 깔 때 생성해준다.
$ apt-get remove --purge nginx nginx-full nginx-common
$ apt-get install nginx
Nginx 에러 로그
/var/log/nginx/access.log
/var/log/nginx/error.log
'Server dev. > NGINX' 카테고리의 다른 글
Nginx 초기 설정 https (0) | 2024.01.31 |
---|---|
[NGINX] Express 에서 사용자 IP 불러오기 오류 해결 (0) | 2023.05.18 |
[NGINX] 413 Request Entity Too Large (0) | 2021.07.20 |
https 인증서 자동 갱신 (Let's Encrypt) (Crontab사용) (0) | 2021.06.15 |
- Total
- Today
- Yesterday
- CUDA
- nvidia
- pytorch
- 3Dvision
- ubuntu
- 우분투
- nginx
- error
- git
- Anaconda
- numpy
- Docker
- MacOS
- GaussianSplatting
- Computer Vision
- 2-stage Detector
- vscode
- Android
- Neural Radiance Field
- MySQL
- java
- SSH
- GPU
- Macbook
- Object Detection
- Novel View Synthesis
- Python
- nerf
- Deep Learning
- Machine Learning
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |