腾讯云控制台配置
登录腾讯云控制台
访问负载均衡》实例管理:
点击【ID/名称】
切换页签【监听管理器】>【HTTP/HTTPS监听器】
配置路径:
1. 配置协议
2. 配置转发路径
nginx配置
在nginx配置文件中 http{节点下:
这样转发请求时,header不会丢失
underscores_in_headers on;
添加sever节点:
server {
listen 9007;
server_name localhost;
location /ya {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
# 这里对应的是springboot项目 ,访问时, http://localhost:9008/ya
proxy_pass http://localhost:9008;
}
}
springboot 配置
跨域配置:
将
corsConfiguration.addAllowedOrigin("*");
改为:
corsConfiguration.addAllowedOriginPattern("*");
具体为:
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
// corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedOriginPattern("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setAllowCredentials(true);
source.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(source);
}
}
yml配置:
server:
port: 9008
servlet:
context-path: /ya
相关文章
暂无评论...