[EC2 / linux] springboot 배포 오류 : Failed to start bean 'webServerStartStop, java.net.SocketException: Permission denied
기존 개발 서버 포트를 8080으로 사용하고 있었는데, ssl을 붙여주려고 포트를 80으로 변경하고 AWS EC2 code deploy를 진행했다.
근데 에러가 쫙 나면서 배포가 자꾸 안됨..
그래서 찾아보니, 1024 이하의 port는 sudo(root)의 권한이 필요하다고 하는데, code deploy로 배포할 경우 ubuntu 권한으로 배포가 되기 때문에 배포에 권한이 없어서 아래와 같은 에러를 뱉으며 실패하게 된다.
2023-03-03 21:35:56.443 DEBUG 20106 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Mapping servlets: dispatcherServlet urls=[/]
2023-03-03 21:36:03.016 DEBUG 20106 --- [ main] .c.JpaMetamodelMappingContextFactoryBean : Initializing JpaMetamodelMappingContext…
2023-03-03 21:36:03.053 DEBUG 20106 --- [ main] .c.JpaMetamodelMappingContextFactoryBean : Finished initializing JpaMetamodelMappingContext!
2023-03-03 21:36:04.040 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Looking up named query User.findByNickname
2023-03-03 21:36:04.054 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query User.findByNickname
2023-03-03 21:36:04.417 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Looking up named query User.findByUserId
2023-03-03 21:36:04.417 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query User.findByUserId
2023-03-03 21:36:04.425 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Looking up named query User.findByEmail
2023-03-03 21:36:04.425 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query User.findByEmail
2023-03-03 21:36:04.613 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Looking up named query Role.findByName
2023-03-03 21:36:04.613 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query Role.findByName
2023-03-03 21:36:04.623 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Looking up named query Role.findByRoleIdIn
2023-03-03 21:36:04.624 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query Role.findByRoleIdIn
2023-03-03 21:36:06.625 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query Bookmark.findAllByUserIdOrderByCreatedAtDesc
2023-03-03 21:36:06.637 DEBUG 20106 --- [ main] o.s.d.r.c.s.RepositoryFactorySupport : Finished creation
2023-03-03 21:36:06.935 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query Comment.findAllByRefIdAndPostType.count
2023-03-03 21:36:06.948 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Looking up named query Comment.getByUserAndCommentIdAndDeletedAtIsNull
2023-03-03 21:36:06.948 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query Comment.getByUserAndCommentIdAndDeletedAtIsNull
2023-03-03 21:36:06.952 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Looking up named query Comment.getByCommentId
2023-03-03 21:36:06.952 DEBUG 20106 --- [ main] o.s.d.jpa.repository.query.NamedQuery : Did not find named query Comment.getByCommentId
2023-03-03 21:36:07.997 DEBUG 20106 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : 41 mappings in 'requestMappingHandlerMapping'
2023-03-03 21:36:08.768 WARN 20106 --- [ main] o.s.s.c.a.web.builders.WebSecurity : You are asking Spring Security to ignore Ant [pattern='/resource/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2023-03-03 21:36:08.769 INFO 20106 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure Ant [pattern='/resource/**']
2023-03-03 21:36:08.769 WARN 20106 --- [ main] o.s.s.c.a.web.builders.WebSecurity : You are asking Spring Security to ignore Ant [pattern='/static/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2023-03-03 21:36:08.774 INFO 20106 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure Ant [pattern='/static/**']
2023-03-03 21:36:08.774 WARN 20106 --- [ main] o.s.s.c.a.web.builders.WebSecurity : You are asking Spring Security to ignore Ant [pattern='/css/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2023-03-03 21:36:08.774 INFO 20106 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure Ant [pattern='/css/**']
2023-03-03 21:36:08.774 WARN 20106 --- [ main] o.s.s.c.a.web.builders.WebSecurity : You are asking Spring Security to ignore Ant [pattern='/js/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2023-03-03 21:36:08.776 INFO 20106 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure Ant [pattern='/js/**']
2023-03-03 21:36:08.776 WARN 20106 --- [ main] o.s.s.c.a.web.builders.WebSecurity : You are asking Spring Security to ignore Ant [pattern='/favicon.ico']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2023-03-03 21:36:08.776 INFO 20106 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure Ant [pattern='/favicon.ico']
2023-03-03 21:36:08.843 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [permitAll] for Ant [pattern='/register/**']
2023-03-03 21:36:08.893 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [permitAll] for Ant [pattern='/login/**']
2023-03-03 21:36:08.893 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [permitAll] for Ant [pattern='/refresh']
2023-03-03 21:36:08.894 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [permitAll] for Ant [pattern='/swagger-ui/**']
2023-03-03 21:36:08.894 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [permitAll] for Ant [pattern='/swagger-resources/**']
2023-03-03 21:36:08.895 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [permitAll] for Ant [pattern='/v3/**']
2023-03-03 21:36:08.895 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [hasRole('ROLE_ADMIN')] for Ant [pattern='/admin/**']
2023-03-03 21:36:08.897 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [hasRole('ROLE_USER')] for Ant [pattern='/user/**']
2023-03-03 21:36:08.897 DEBUG 20106 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression [authenticated] for any request
2023-03-03 21:36:08.918 INFO 20106 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@6d617b07, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@340c57e0, org.springframework.security.web.context.SecurityContextPersistenceFilter@7bce9ce4, org.springframework.security.web.header.HeaderWriterFilter@56478522, org.springframework.security.web.authentication.logout.LogoutFilter@595ec862, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@5af38a4a, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@5d800a56, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@7c9372ed, org.springframework.security.web.session.SessionManagementFilter@7aa3857b, org.springframework.security.web.access.ExceptionTranslationFilter@334b392d, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2a9e754e]
2023-03-03 21:36:10.207 DEBUG 20106 --- [ main] o.s.data.auditing.AuditingHandler : No AuditorAware set; Auditing will not be applied
2023-03-03 21:36:10.563 DEBUG 20106 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2023-03-03 21:36:10.981 DEBUG 20106 --- [ main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 1 @ExceptionHandler, 1 ResponseBodyAdvice
2023-03-03 21:36:11.456 DEBUG 20106 --- [ main] o.s.w.s.v.f.FreeMarkerConfigurer : File system access not preferred: using SpringTemplateLoader
2023-03-03 21:36:11.912 ERROR 20106 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.25.jar!/:5.3.25]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.25.jar!/:5.3.25]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.8.jar!/:2.7.8]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.25.jar!/:5.3.25]
... 22 common frames omitted
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.7.8.jar!/:2.7.8]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.7.8.jar!/:2.7.8]
... 24 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1076) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234) ~[tomcat-embed-core-9.0.71.jar!/:na]
... 26 common frames omitted
Caused by: java.net.SocketException: Permission denied
at java.base/sun.nio.ch.Net.bind0(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.bind(Net.java:459) ~[na:na]
at java.base/sun.nio.ch.Net.bind(Net.java:448) ~[na:na]
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227) ~[na:na]
at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:275) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:230) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1227) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1313) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:615) ~[tomcat-embed-core-9.0.71.jar!/:na]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1073) ~[tomcat-embed-core-9.0.71.jar!/:na]
... 28 common frames omitted
그래서 나는 그냥 8080으로 배포하고, 80으로 들어오면 8080으로 라우팅 되게 설정을 변경했다.
80 port 와 8080 port를 열어주고
sudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
80으로 들어오는 요청을 8080으로 라우팅 해주면 된다.
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
이렇게 하면 80으로 들어와도, 8080으로 들어와도 전부 잘 구동된다.
댓글