System deployed in elasticbeanstalks+github+tomcat+AWS I've tried the Gzip compression using ebextensions files but it not works.
option_settings:
aws:elasticbeanstalk:environment:proxy:
GzipCompression: 'true'
ProxyServer: nginx
and
files:
/etc/nginx/conf.d/gzip.conf:
content: |
gzip_types application/json application/xml text/html text/xml text/plain application/javascript text/css;
(similar configs tried with .ebextensions/tomcat-settings.config as well, but not works)
So moved to Gzip compression using code level. So added dependencies on pom and create a bean in the Application class
@Bean
public Filter compressingFilter() {
CompressingFilter compressingFilter = new CompressingFilter();
return compressingFilter;
}
<dependency>
<groupId>net.sourceforge.pjl-comp-filter</groupId>
<artifactId>pjl-comp-filter</artifactId>
<version>1.6.4</version>
</dependency>
Then Gzip compression works fine in each and every API response. But it causes a negative impact on the web app because the same app provides web-view too, (Spring Boot + Spring Security + Spring MVC and deployed as .war file). As a result of GZIP now css js not loading and page not appear as expected under SSL. but its http one works fine but getting more time to load css/js files.
So I've tried removing the below entries in the application properties file to avoid any double compression in there.
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css
and tried adding some filter in code level
@Bean
public FilterRegistrationBean filterRegistrationBean () {
CompressingFilter compressingFilter = new CompressingFilter();
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(compressingFilter);
Map<String, String> initParams = new HashMap();
initParams.put("exclusions", "*.js,*.css");
registrationBean.setInitParameters(initParams);
return registrationBean;
}
also tried with web-security ignore filtering
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**", "/js/**");
}
Therefore let me know any workaround or some code level filtering to avoid this issue.
Error Stack
s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
o.s.s.w.a.i.FilterSecurityInterceptor : Authorized filter invocation [GET /myapp/css/bootstrap.min.css] with attributes [permitAll]
o.s.security.web.FilterChainProxy : Secured GET /myapp/css/bootstrap.min.css
o.s.web.servlet.DispatcherServlet : GET "/myapp/css/bootstrap.min.css", parameters={}
.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@7534e708
o.s.security.web.FilterChainProxy : Securing GET /myapp/js/bootstrap.min.js
s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND