今天和后端调试时遇到了跨域的问题,本来以为和以往一样只要后端设置一下就行了。没想到这次因为是采用复杂的请求方式,在遇到跨域请求时后端会自动发送options对服务器进行验证。而java在遇到options请求时会自动拒绝。
介绍一下nginx:Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。
这里是下载地址:http://nginx.org/en/download.html
安装完成之后,打开nginx-1.16.0\conf\nginx.conf 文件进行配置
server {
listen 8080; //监听8080端口
server_name localhost; //监听的地址 localhost
#charset koi8-r;
#access_log logs/host.access.log main;
location ^~ /apis/ { //匹配的对象
proxy_pass http://192.168.20.14:8080/; //进行转发之后的地址,主要最后要加/
}
location / {
root html/a;
index index.html index.htm;
}
}
以上配置完成之后访问 http://localhost:8080/apis/... 会自动访问 http://192.168.20.14:8080/...