[JavaScript] Nginx實現跨域設置

假如跨域請求的接口爲:http://xxx.cn/was5/web/searchhtml

Nginx配置:nginx

在conf/nginx.conf文件中web

location / {
    root   html;
    index  index.html index.htm;
}

 

後面增長跨域

location /was5{
    proxy_pass   http://xxx.cn;
}

配置以後,將js請求接口改成:/was5/web/search 瀏覽器

重啓Nginx服務,瀏覽器訪問http://localhost便可,默認端口80,可在conf/nginx.conf更改端口spa

相關文章
相關標籤/搜索