Проблема конфигурации: браузер возвращает ERR_CONNECTION_REFUSEDJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Проблема конфигурации: браузер возвращает ERR_CONNECTION_REFUSED

Сообщение Anonymous »

Когда мое приложение Angular вызывает конечную точку, браузер возвращает ошибку:

GET https://127.0.0.1:8443/auth/login net ::ERR_CONNECTION_REFUSED

Также см.:
Изображение

Это мои конфигурации:

Код: Выделить всё

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
@AllArgsConstructor
@CrossOrigin
@SpringBootApplication(scanBasePackages = {"com.dynamicquotation.dq"})
public class SecurityConfiguration implements WebMvcConfigurer {
private final JwtFilter jwtFilter;
private final DataSource dataSource;

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("https://example.com")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
}

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.cors(withDefaults())  // Apply CORS configuration
.csrf(AbstractHttpConfigurer::disable);

// Enforce HTTPS
http.requiresChannel(channel -> channel.anyRequest().requiresSecure());

http.sessionManagement(sess -> sess.sessionAuthenticationStrategy(sessionAuthenticationStrategy()));

// Authorization
http.authorizeHttpRequests(auth ->
auth
.requestMatchers("/", "/api/auth/oauth", "/api/auth/user-exists", "/api/user-profile/**").authenticated()
.requestMatchers("/api/auth/**", "/logout", "api/contact", "/api/quotation/single-quotation/**").permitAll()
.anyRequest().authenticated()
);

http.httpBasic(withDefaults());

// logout
http.logout(l -> l
.logoutUrl("/api/logout")
.logoutSuccessUrl("/")
.clearAuthentication(true)
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.logoutRequestMatcher(new AntPathRequestMatcher("/api/logout"))
.logoutSuccessHandler((request, response, authentication) -> response.setStatus(HttpServletResponse.SC_OK))
.addLogoutHandler((request, response, authentication) -> {
// Additional logout handler if needed
}).permitAll());

http.oauth2Login(withDefaults());
http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);

return http.build();
}
application.yml:

Код: Выделить всё

server:
error:
include-message: on-param
tomcat:
max-swallow-size: 50MB
port: 8080
address: 0.0.0.0
Конфигурации Nginx:

Код: Выделить всё

# HTTP server block
server {
listen 80;
server_name api.example.com;

# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}

# HTTPS server block
server {
listen 443 ssl;
server_name api.example.com;

# SSL certificate paths
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;

# CORS headers
add_header Access-Control-Allow-Origin "https://example.com" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
add_header Access-Control-Allow-Headers "Authorization, Content-Type" always;
add_header Access-Control-Allow-Credentials "true" always;

location / {
# Handle preflight (OPTIONS) requests
if ($request_method = OPTIONS) {
return 204;
}

# Proxy pass to Spring Boot application
proxy_pass http://127.0.0.1:8080;
}
}
Я не понимаю, почему браузер указывает на https://127.0.0.1:8443, ведь клиент находится на https://example.com, а API — на https ://api.example.com.
Что вызывает эту ошибку и как ее исправить?

Подробнее здесь: https://stackoverflow.com/questions/790 ... on-refused
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»