前后端分離模式下的跨域訪問:
~~~
upstream tomcat_server {
server 10.25.39.131:8080;
server 10.25.39.132:8080;
}
server {
listen 80;
server_name www.wxvote.com;
##注意:
##"proxy_pass"中的路徑只能到端口,否則報: cannot have URI part in location given by regular expression
location ~* \.(html|css|js|gif|jpg|jpeg|mp4)$ {
proxy_pass http://10.25.39.140:8020;
}
location / {
proxy_pass http://tomcat_server/;
proxy_set_header Host $host;
}
}
~~~
訪問現有的ajax服務
例如:訪問心知天氣。
~~~
server
{
listen 80;
server_name localhost;
location ~* \.(html|css|js|gif|jpg|jpeg|mp4)$ {
root weather;
}
location /
{
proxy_pass http://api.seniverse.com;
}
}
~~~
springboot配置跨域
```
package com.example.demo.config;
import static org.springframework.web.cors.CorsConfiguration.ALL;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@ComponentScan(basePackages={"com.example.demo"})
public class SpringConfig {
//增加跨域權限配置
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 限制了路徑和域名的訪問
/*registry.addMapping("/api*").allowedOrigins("http://localhost:8081");*/
//設置允許跨域的路徑
registry.addMapping("/**")
//設置允許跨域請求的域名
// .allowedOrigins(ALL)
//設置允許跨域請求的域名,如果想要傳遞cookie,就不能再用*
.allowedOrigins("http://localhost:9527")
//是否允許證書 不再默認開啟
.allowCredentials(true)
//設置允許的方法
.allowedMethods(ALL)
//設置允許的header
.allowedHeaders(ALL)
//.exposedHeaders(HttpHeaders.SET_COOKIE, "token")
//跨域允許時間
.maxAge(3600);
registry.addMapping("/**")
//設置允許跨域請求的域名
// .allowedOrigins(ALL)
//設置允許跨域請求的域名,如果想要傳遞cookie,就不能再用*
.allowedOrigins("http://localhost:8081")
//是否允許證書 不再默認開啟
.allowCredentials(true)
//設置允許的方法
.allowedMethods(ALL)
//設置允許的header
.allowedHeaders(ALL)
//.exposedHeaders(HttpHeaders.SET_COOKIE, "token")
//跨域允許時間
.maxAge(3600);
}
};
}
}
```
- 第一章 Linux
- 1. Linux安裝和網絡配置
- 2. Linux基本命令
- 3. Xshell和winscp
- 4. VIM編輯器
- 5. 安裝軟件
- 5.1 安裝JDK
- 5.2 安裝TOMCAT
- 5.3 安裝MySql
- 5.4 安裝Nginx
- 5.5 部署工程
- 第二章 Nginx
- 1. 安裝Nginx
- 2. 配置Nginx
- 2.1 配置靜態服務器
- 2.2 配置反向代理
- 2.3 配置負載均衡
- 2.4 配置動靜分離
- 2.5 跨域訪問
- 第三章 Redis
- 1. 安裝Redis
- 2. JAVA操作Redis
- 3. Redis事務
- 4. Redis持久化
- 5. 主從復制和集群
- 6. Redis實現Session共享
- 第四章 MySQL主從復制
- 4.1 MyCat安裝
- 4.2 MySQL主從復制
- 4.3MySQL讀寫分離
- 第五章 ActiveMQ
- 5.1 Queue
- 5.2 Topic
- 第六章 FastDFS圖片服務器
- 第七章