728x90
반응형
SMALL

도메인을 연결하기 위해서는 Certbot을 이용해야하기 때문에 우분투에 설치 먼저해줘야합니다.

  1. Certbot을 설치하고 업데이트하세요.
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx

2. Certbot을 사용하여 인증서를 생성하세요.

sudo certbot --nginx

Certbot을 실행할 때 도메인 이름을 입력하라는 메시지가 표시됩니다. 여기에 도메인 이름을 입력하고 인증서 생성 프로세스를 완료하세요.

If you really want to skip this, you can run the client with
--register-unsafely-without-email but you will then be unable to receive notice
about impending expiration or revocation of your certificates or problems with
your Certbot installation that will lead to failure to renew.

Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): 이메일 주소

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
<https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf>. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

ubuntu@ip-172-31-46-142:~$ sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): 도메인이름
Requesting a certificate for 도메인이름

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/도메인이름/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/도메인이름/privkey.pem
This certificate expires on 2023-07-07.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for 도메인이름 to /etc/nginx/sites-enabled/default
Congratulations! You have successfully enabled HTTPS on 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

저장된 위치를 메모장에 따로 기록해주세요! 

3. 생성된 인증서와 키의 경로를 확인하고, Nginx 구성 파일의 ssl_certificatessl_certificate_key 지시문에 올바른 경로를 설정하세요.

예를 들면, 다음과 같이 설정할 수 있습니다.

ssl_certificate /etc/letsencrypt/live/hype.r-e.kr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/hype.r-e.kr/privkey.pem;

4. Nginx 구성을 테스트하고, 문제가 없다면 다시 로드하여 변경 사항을 적용하세요.

sudo nginx -t
sudo systemctl reload nginx

 

5. 도메인이름과 도메인이름:8080을 확인해주세요~

확인 후 포트포워딩!!

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

확인하면 도메인 이름으로 스프링 부트가 적용이 된 것을 확인할 수 있습니다!

아직 https 로 리다이렉트를 하지 않아서 http 입니다~ 
그 후에는 로드벨런서 블루/ 그린을 적용할 예정입니다! (무중단 배포 화이팅..!!)

728x90
반응형
LIST

'개발 > sw' 카테고리의 다른 글

리눅스  (0) 2023.05.11
우분투 nginx(4) 리다이렉트  (0) 2023.04.15
우분투 nginx (2) 스프링부트 연결하기  (0) 2023.04.09
우분투 nginx (1) 설치 및 포트 변경  (0) 2023.04.09
http → https 리다이렉트 오류  (0) 2023.04.06
728x90
반응형
SMALL

무중단 배포를 하기 전 먼저 스프링부트를 연결을 연습을 했습니다.

서버 블록 작성

기본적으로 Ubuntu 시스템에서 Nginx 서버 블록 구성 파일은 /etc/nginx/sites-enable/ 디렉토리에 대한 심볼 링크를 통해 사용할 수 있는 /etc/nginx/sites-available/ 디렉토리에 저장됩니다.

원하는 편집기를 열고 다음 서버 블록 파일을 만듭니다.

/etc/nginx/sites-available/도메인이름.conf 의 파일을 만들기 위해서는 
앞에 sudo nano 를 붙여주면 수정이 가능하다!

sudo nano /etc/nginx/sites-available/도메인이름.conf

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 / {
^X Exition     M# First attempt to serve request as file, then  ^J Justify      ^
                # as directory, then fall back to displaying a 404.
                proxy_pass <http://인스턴스> IP 주소 ex) 127.0.0.0;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                try_files $uri $uri/ =404;
        }

작성 후
ctrl + ^ + x
ctrl + y
저장!

proxy_pass http://인스턴스 IP 주소 ex) 127.0.0.0;
여기에 사용할 인스턴스 주소를 넣고 저는 스프링 부트를 사용하기 때문에 127.0.0.0:8080을 넣어주면
엔진엑스와 스프링 부트 연결이 됩니다!

재시작은 필수!!

sudo systemctl reload nginx

상태확인!

sudo systemctl status nginx.service


127.0.0.0에 접속 했을 때 엔진엑스 화면이 나오고 

127.0.0.0:8080에 접속했을 때 흔히 보이는 화면이 나옵니다.

저는 시큐리티를 사용하고 따로 필터에서 제외를 해주지 않았기 때문에 127.0.0.0:8080/login 화면으로 확인했습니다!

이 두개를 하나로 합치기 위해 포트포워딩이 필요합니다! -> 도메인 연결하고 나서 하는 걸 추천 합니다! 헷깔려요...!!

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

 

728x90
반응형
LIST
728x90
반응형
SMALL

Nginx 서버 블록을 사용하면 한 컴퓨터에서 두 개 이상의 웹 사이트를 실행할 수 있습니다. 서버 블록을 사용하여 사이트 문서 루트(웹 사이트 파일이 들어 있는 디렉토리)를 지정하고, 각 사이트에 대해 별도의 보안 정책을 만들고, 각 사이트에 대해 서로 다른 SSL 인증서를 사용하는 등의 작업을 수행할 수 있습니다.

필수 구성 요소

자습서를 계속 진행하기 전에 다음 필수 구성 요소를 충족했는지 확인합니다.

- 공용 서버 IP를 가리키는 도메인 이름이 있습니다. example.com을 사용할 것입니다.

- 다음 지침에 따라 Nginx를 설치했습니다.

- sudo 권한을 가진 사용자로 로그인했습니다.

 

일부 설명서에서는 서버 블록을 가상 호스트라고 합니다. 가상 호스트는 Apache 용어입니다.

디렉토리 구조를 작성

문서 루트는 도메인 이름에 대한 웹 사이트 파일이 저장되고 요청에 대한 응답으로 제공되는 디렉토리입니다. 문서 루트를 원하는 위치로 설정할 수 있습니다.

 다음 디렉토리 구조를 사용합니다.

/var/www/
├── domain1.com
│ └── public_html
├── domain2.com
│ └── public_html
├── domain3.com
│ └── public_html

NGINX 설치 및 실행

# 업데이트 해주기
sudo apt-get update
# 자바 설치
sudo apt-get install openjdk-11-jdk
# 자바 버전 확인
java -version
sudo apt-get install nginx

sudo service nginx start

sudo service nginx status

Nginx의 포트를 80에서 8080으로 변경

sudo nano /etc/nginx/nginx.conf
http {
    server {
        listen 8080;
        server_name example.com;
        
        ...
    }
}

설정 파일 저장 후 Nginx 재시작

sudo systemctl restart nginx

 

728x90
반응형
LIST

+ Recent posts