开发过程中,会有多个服务进行交互,往往通过RESTFul方式进行交互,但是只满足后台调用是不够的,有时候需要支持js调用外部接口的情况。 主流浏览器在使用Ajax发起http请求时,会有安全策略,如果两个应用的根域名不同,请求会被拦截。 2、解决方案现在常见的解决方案有jsonp,和代理方式。这篇文章主要围绕代理方式解决展开。 3、配置server { add_header 'Access-Control-Allow-Origin' "$http_origin"; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Max-Age' 1728000; listen 80; server_name localhost; #charsetkoi8-r; #access_log logs/host.access.log main; location / { root html; index index.htmlindex.htm; } location /sym { proxy_pass http://172.16.32.245:8082/sym; } location /rwglfw/ { proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_passhttp://172.16.33.91:6379/rwglfw/; } location /ajbjfw/ { proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://172.16.33.91:6379/ajbjfw/; } location /glajfw/ { proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://172.16.33.91:6409/glajfw/; } location /spxt/ { proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://172.16.33.89:6345/spxt/; } } (责任编辑:IT) |