Skip to content

Commit

Permalink
Merge pull request #150 from VeryyyGood/feature/147
Browse files Browse the repository at this point in the history
[#147] AWS의 ALB/NLB가 HTTPS 요청을 처리하고, Nginx는 HTTP 요청만 처리하도록
  • Loading branch information
persi0815 authored Jul 15, 2024
2 parents fe04a15 + 64dfa0b commit 7d02b03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 51 deletions.
48 changes: 1 addition & 47 deletions .platform/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# HTTP와 HTTPS 요청을 모두 처리. HTTP와 HTTPS 요청을 각각 처리.

# AWS의 ALB/NLB가 HTTPS 요청을 처리하고, Nginx는 HTTP 요청만 처리
user nginx;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
Expand Down Expand Up @@ -75,49 +74,4 @@ http {
# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/healthd.conf;
}

# HTTPS 서버 블록
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name reborn.persi0815.site;

location / {
proxy_pass http://springboot;
if ($request_method = 'OPTIONS') {
# OPTIONS 요청에 대한 CORS 헤더 추가
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Content-Length' '0';
add_header 'Content-Type' 'text/plain charset=UTF-8';
return 204;
}

# CORS 관련 헤더 추가
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
add_header 'Access-Control-Allow-Credentials' 'true';
proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

access_log /var/log/nginx/https_access.log main;

client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
gzip_comp_level 4;

# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/healthd.conf;
}
}
20 changes: 16 additions & 4 deletions src/main/java/reborn/backend/global/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package reborn.backend.global.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/*
@OpenAPIDefinition(
servers = {
@Server(url = "https://reborn.persi0815.site", description = "reborn https 서버입니다."),
@Server(url = "http://reborn.persi0815.site", description = "reborn http 서버입니다.")
}
)
*/
@Configuration
public class SwaggerConfig {

Expand All @@ -42,10 +44,20 @@ public OpenAPI api() {
.scheme("bearer")
.bearerFormat("JWT")); // 토큰 형식을 지정하는 임의의 문자(Optional

// 서버 URL 설정
io.swagger.v3.oas.models.servers.Server httpsServer = new io.swagger.v3.oas.models.servers.Server();
httpsServer.setUrl("https://reborn.persi0815.site");
httpsServer.setDescription("reborn https 서버입니다.");

io.swagger.v3.oas.models.servers.Server httpServer = new Server();
httpServer.setUrl("http://reborn.persi0815.site");
httpServer.setDescription("reborn http 서버입니다.");

return new OpenAPI()
.info(info)
.addSecurityItem(securityRequirement)
.components(components);
.components(components)
.servers(List.of(httpsServer, httpServer));
}

@Bean
Expand Down

0 comments on commit 7d02b03

Please sign in to comment.