nginx部署VUE跨域访问api
H5端配置跨域
nginx跨域配置
server {
listen 80;
charset utf-8;
server_name you_dome_name;
#location /tasklist.jsp { #这个没用。这是我们的业务需求
#rewrite /webpage/task/tasklist.jsp /dist/index.jsp;
#}
location / {
try_files $uri $uri/ /index.html;
root /application/nginx/html/dist; ###dist文件位置
index index.html index.htm index.php;
add_header 'Access-Control-Allow-Origin' 'http://you_dome_name'; ### 这里的链接可以是* 表示允许所有域名
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET,POST'; ###支持get post方式
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
如果服务端是tomcat ,tomcat跨越也需要配置
vim /application/tomcat1/conf/web.xml
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Head
ers</param-value>
</init-param>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
nginx部署VUE跨域访问api的更多相关文章
- nginx部署vue跨域proxy方式
server { listen 80; charset utf-8; #server_name localhost; server_name you_h5_name; ###VUE项目H5域名 err ...
- vue跨域访问
第一次创建vue项目,画完静态页面一切顺利,准备和后台进行联调,问题来了,无论怎么调试使用Axios,jQuary还是使用原生的Ajax请求都访问不通(前提条件,另外一个人的电脑当成服务器,进行访问) ...
- Vue跨域访问,axios&cors
先安装node.js和npm,这个不用说了,直接在创建vue项目,然后实践一下跨域访问. 如果npm安装较慢,可安装淘宝镜像,执行下面命令: npm install -g cnpm --registr ...
- java 解决nginx代理的跨域访问问题
一.什么是跨域 跨域是浏览器对JavaScript同源策略的限制 二.什么情况下会产生跨域 域名不同 wwww.baidu.com www.jd.com 域名相同,访问的端口不同 wwww.baidu ...
- nginx:支持跨域访问
在http节点中配置: #支持跨域访问 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Header ...
- .net core webapi+vue 跨域访问
最近在做一个前后端分离的示例,以下代码完美解决跨域的问题 一.后端服务 1.首先我们建一个.net core webapi的项目 2.项目引用Microsoft.AspNetCore.Cors 包 3 ...
- Apache + PHP Yii框架跨域访问API
其实不用在Yii框架中设置任何东西,直接用Ajax调用不同域名的API即可 但是Apache中要这么设置: 首先编辑httpd.conf 去掉这一句的注释:LoadModule headers_ ...
- nginx 配置ajax跨域访问php接口
在nginx.conf里面,找到server项,并在里面添加如下配置 location ~ \.php?($|/) { #try_files $uri =; #handel cosr by mao a ...
- vue 跨域访问http
axios用法: npm install axios --save-dev 2.导入: import axios from 'axios'; 3.使用($(form)需要先按装jQuery) axio ...
随机推荐
- Flask学习之十三 日期和时间
英文博客地址:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xiii-dates-and-times 中文翻译地址: ...
- Part10-字符型设备驱动模型-part10.1-使用字符型设备
‘ ’
- python selenium 测试配置信息(URL和浏览器)
config.ini # this is config file, only store browser type and server URL [browserType] #browserName ...
- Android Animation动画详解(一): 补间动画
前言 你有没有被一些APP中惊艳的动画效果震撼过,有没有去思考,甚至研究过这些动画是如何实现的呢? 啥?你没有思考,更没有研究过? 好吧,那跟着我一起来学习下如何去实现APP中那些让我们惊羡的动画特效 ...
- Spring < context:annotation-config> 、< context:component-scan>、< mvc:annotation-driven />注解配置
Spring 中在使用注解(Annotation)会涉及到< context:annotation-config> 和 < context:component-scan>配置, ...
- Codeforces Round #174 (Div. 1 + Div. 2)
A. Cows and Primitive Roots 暴力. B. Cows and Poker Game 模拟. C. Cows and Sequence 线段树维护. D. Cow Progra ...
- Python--day40--复习和回调函数实例
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- npm install 报错(npm ERR! errno -4048,Error: EPERM: operation not permitted)
问题现象 原因 1.初次看报错日志内容,定义权限为问题,后来查资料才知道是缓存问题. 解决方法 1.简单直接 直接删除 npmrc文件 tips: 不是nodejs安装目录npm模块下的那个npmrc ...
- [android] eclipse里面的安卓模拟器起不来
提示信息可能是: The connection to adb is down, and a severe error has occured. 网上看了下,常见原因有两个: 1,系统里面另外有个叫ad ...