이러면 로컬에선 서버 URL이 localhost:8080이고 배포 시에는 배포 도메인으로 바뀌므로 CORS 문제를 해결할 수 있다.
@Configuration
@RequiredArgsConstructor
@SecurityScheme(
name = "jwt-cookie",
type = SecuritySchemeType.APIKEY,
in = SecuritySchemeIn.COOKIE
)
public class SwaggerConfig {
private final AppConfig appConfig;
@Bean
public OpenAPI serverApiConfig() {
Server server = new Server();
server.setUrl(appConfig.getBackUrl());
server.description("백엔드 도메인");
return new OpenAPI()
.addServersItem(server)
.info(new Info().title("PAWLAND API")
.description("PAWLAND API SWAGGER UI입니다."));
}
}
# 4. certbot 명령어가 실행될 수 있게 세팅한다 sudo ln -s /snap/bin/certbot /usr/bin/certbot
# 5. 아래 명령어를 입력하면 certbot이 nginx 구성을 자동으로 수정한다. # nginx가 아닌 apache를 웹서버로 사용할 경우, sudo certbot --apache 가 된다 sudo certbot --nginx -d midcon.store -d www.midcon.store
# certbot은 CLI몇 줄로 SSL을 적용해줄 뿐 아니라 자동 리뉴얼까지 해준다 # 처음 설치할 때부터 이러한 cron job 처리를 위한 내용을 site-available/default 에 자동으로 설정해준다 # 아래 명령어로 자동 리뉴얼이 적용되고 있는지 확인할 수 있다 sudo certbot renew --dry-run
5번 커맨드를 입력하면 아래처럼 이메일, 약관 동의 여부 등등을 입력하는 부분이 있다.
당황하지말고 적당히 읽어보고 입력하면 된다.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): hyukkind@naver.com # 이메일 입력
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.pdf. You must agree in
order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y # ACME 약관에 동의하는지 N선택시 진행불가
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 # 이메일을 통해 Let's Encrypt 프로젝트 정보를 받아볼지
Account registered.
Requesting a certificate for midcon.store and www.midcon.store
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/midcon.store/fullchain.pem
Key is saved at: /etc/letsencrypt/live/midcon.store/privkey.pem
This certificate expires on 2024-08-15.
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 midcon.store to /etc/nginx/sites-enabled/default
Successfully deployed certificate for www.midcon.store to /etc/nginx/sites-enabled/default
Congratulations! You have successfully enabled HTTPS on https://midcon.store and https://www.midcon.store
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2. 결과 확인
2-1./etc/nginx/sites-available/default 확인
아래 사진은/etc/nginx/sites-available/default로 들어가본 결과이다.
localtion /ws 부분은 본인이 웹소켓 설정하느라 추가한 부분이고 아래 부분부터 보면 되는데
아래처럼 certbot이 nginx 설정까지 자동으로 변경한 알 수 있다.
HTTP로 요청하면 HTTPS로 리다이렉트 시키는 설정도 certbot이 자동으로 해두었다.
2-2. HTTP/HTTPS 요청 시
이제 HTTP 로 요청하면 자동으로 HTTPS 로 리다이렉트 되고, HTTPS 요청도 잘 되는걸 확인할 수 있다.
3. 추가
만약 인증서를 삭제하고 싶다면 아래 명령어를 입력하면 된다.
sudo certbot delete
그럼 아래와 같은 창을 확인할 수 있고, 여기서 삭제하고 싶은 인증서의 번호를 입력하면 된다.