vue.js使用代理和使用Nginx来解决跨域的问题-创新互联
使用Nginx 反向代理解决跨域问题(vue.js使用代理去掉vue.js因为跨域而触发的options请求)

我们的项目还是需要node.js作为容器的
一、Windows 下安装Nginx (官网下载稳定版http://nginx.org/en/download.html)
二、修改config里的nginx.conf文件的server
server {
listen 8899;// 你的端口
server_name localhost;
root C:/ZOBSF_F/dist;//你打包部署的文件路径
#charset koi8-r;
#access_log logs/host.access.log main;
# 匹配 api 路由的反向代理到API服务
location ^~/api {
proxy_pass http://119.23.227.141:10001/;//你的后端IP和端口
}
#根据路由设置,避免出现404
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
标题名称:vue.js使用代理和使用Nginx来解决跨域的问题-创新互联
转载源于:http://www.jxjierui.cn/article/copjce.html


咨询
建站咨询
