登峰造极境

  • WIN
    • CSharp
    • JAVA
    • OAM
    • DirectX
    • Emgucv
  • UNIX
    • FFmpeg
    • QT
    • Python
    • Opencv
    • Openwrt
    • Twisted
    • Design Patterns
    • Mysql
    • Mycat
    • MariaDB
    • Make
    • OAM
    • Supervisor
    • Nginx
    • KVM
    • Docker
    • OpenStack
  • WEB
    • ASP
    • Node.js
    • PHP
    • Directadmin
    • Openssl
    • Regex
  • APP
    • Android
  • AI
    • Algorithm
    • Deep Learning
    • Machine Learning
  • IOT
    • Device
    • MSP430
  • DIY
    • Algorithm
    • Design Patterns
    • MATH
    • X98 AIR 3G
    • Tucao
    • fun
  • LIFE
    • 美食
    • 关于我
  • LINKS
  • ME
Claves
长风破浪会有时,直挂云帆济沧海
  1. 首页
  2. Platforms
  3. LINUX
  4. OAM
  5. 正文

vue-nginx前后端分离部署方法

2018-02-28

使用vue前后端分离部署时,若前端与api不在同一个域,那么会遇到很多的问题(比如跨域引起的问题)。但是我们可以采用nginx反向的方式,解决这个烦恼。

nginx主要配置内容如下:

        location / {
            root   D:/thSites/xbjs.web/dist;
            index  index.html index.htm;
	}
	location ~ ^/(api|css|font-awesome|js|images|)/  {
		proxy_redirect off;
		proxy_set_header Host $http_host;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Upgrade $http_upgrade; 
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:8080;
	}

如上,后台api的路由,如/api/xx 使用nginx反向至127.0.0.1:8080即可解决。

疑问:

1、反向时,被反向的路径在api服务器如何对应呢?

解析:

比如api的路径是/api/user/add,nginx配置中将/api/反向到127.0.0.1:8080,那么在vue中调用api时,路劲应为/api/user/add,而非/api/api/user/add

标签: 暂无
最后更新:2025-03-13

代号山岳

知之为知之 不知为不知

点赞
< 上一篇
下一篇 >

COPYRIGHT © 2099 登峰造极境. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蜀ICP备14031139号-5

川公网安备51012202000587号