前后端實現(xiàn)了分離, 前端訪問路徑www.domain.com, 后端API請求地址:api.domain.com
通過nginx的反向代理實現(xiàn)解決跨域請求的問題
nginx配置如下
listen 80;
server_name www.domain.com;
location ^~ / {
root /usr/local/src/webroot;
access_log off;
expires -1;
}
location ^~/api/{
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://api.domain.com/;
}
}
在請求后端API的地址:www.domain.com/api/xx/bb/dd
真正的后端訪問地址:api.domain.com/xx/bb/dd