五、 跨域访问
前后端分离模式下的跨域访问:
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;
}
}