nginx服务器配置传递给下一层的信息的一些参数-设置哪些跨域的域名可访问
http {
server_tokens off; #隐藏nginx版本
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400
server {
listen 80;
server_name localhost ;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' '*';
server {
server_tokens off;
listen 443 ssl;
server_name xxxx.xx.com;
ssl_certificate /usr/local/nginx/cert/xxx.cer;
ssl_certificate_key /usr/local/nginx/cert/xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
charset UTF-8;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' '*';
}
}
@Configuration public class CorsConfig { @Value("#{'${xxx.allowed-origins}'.split(',')}") private List<String> allowedorigins; @Bean public CorsWebFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); config.addAllowedMethod("*"); if(allowedorigins!=null&&allowedorigins.size()>0){ for (String origin:allowedorigins ) { config.addAllowedOrigin(origin); } } config.addAllowedHeader("*"); config.setAllowCredentials(true); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); source.registerCorsConfiguration("/**", config); return new CorsWebFilter(source); }