首页 > 系统相关 >nginx部署 vue3 同时 配置接口代理(详细)

nginx部署 vue3 同时 配置接口代理(详细)

时间:2023-07-13 15:22:47浏览次数:43  
标签:set header 配置 接口 nginx api proxy vue3

Vue项目配置.env文件

在项目根目录下创建文件夹(.env.production )

image

## .env.production 生产环境配置
VUE_APP_SYS_URL = sysapi  ##nginx 需要用的的代理表示
VUE_APP_MODE = product   ## 模式
baseUrl 使用 VUE_APP_SYS_URL 变量代替

image

Nginx下载部署和配置api代理

Nginx 下载地址 http://nginx.org/en/download.html
根据需要下载对应版本

image

下载后,解压文件夹

image

build项目

image

image

nginx配置程序需要的api地址(编辑conf/nginx.conf文件)

打开nginx.conf文件

image

更改以下配置

image

        location /sysapi/ {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            #rewrite ^/api/(.*)$ /$1 break;  #重写
            proxy_pass http://127.0.0.1:9992/; # 设置后端服务器的协议和地址
        }

至此完成 vue项目的部署 和 后台api 代理

标签:set,header,配置,接口,nginx,api,proxy,vue3
From: https://www.cnblogs.com/kizuna1314/p/17550491.html

相关文章

  • 接口返回数据后,将其渲染到swiper上,但样式没发生改变
    varswiper=newSwiper("#swiper1",{slidesPerView:3,observer:true,observeParents:true,grid:{rows:2,},spaceBetween:30,pagination:{el:".swiper-pagination",clickable:true,},}......
  • vue3核心概念-Mutation-辅助函数
    你可以在组件中使用 this.$store.commit('xxx') 提交mutation,或者使用 mapMutations 辅助函数将组件中的methods映射为 store.commit 调用(需要在根节点注入 store)辅助函数只能在选项式API中使用<template><h3>Nums</h3><p>{{getCount}}</p><inputtype="......
  • Docker Nginx安装使用以及踩坑点总结
    拉取nginx镜像dockerpullnginx:latest运行镜像暂时不需要配置volume挂载dockerrun--namenginx-p80:80-dnginx参数详解:--namenginx指定容器的名称-p80:80映射端口-d守护进程运行创建volume目录mkdir-p/www/nginx/conf.dmkdir-p/www/nginx/htmlmkd......
  • Nginx:client_body_temp_path 指令的上传文件测试
    结论硬盘必须要有上传文件3倍大小的剩余空间。否则会报错“nospaceleftondevice”。需要注意,这3份数据都会写到硬盘。大文件上传,实时观察硬盘剩余空间watch-n0.1"df-hm/",会看到很大的波动。默认临时文件路径文档Syntax: client_body_temp_pathpath[level1[lev......
  • ubuntu apt安装最新稳定版nginx
    适用于apt安装,根据自身系统可更改命令#!/bin/bash#下载安装nginxkeywgethttp://nginx.org/keys/nginx_signing.key-P/root/script/download#安装keysudoapt-keyadd/root/script/download/nginx_signing.key#添加源release_name=`lsb_release-c|awk-F''......
  • 若依微服务使用openfeign ,写了一个接口,但是其他项目引入的时候显示找不到这个Bean:Coul
    启动报错:org.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'tokenController':Unsatisfieddependencyexpressedthroughfield'sysLoginService';nestedexceptionisorg.springframework.beans.fa......
  • vue3 图片懒加载
    使用vue第三方库useIntersectionObserver创建文件directives/index.js导入第三方库import{useIntersectionObserver}from'@vueuse/core'exportconstlazyPlugin={install(app){app.directive('img-lazy',{mounted(el,binding){......
  • Vue3 实现点击菜单实现切换主界面组件
    子组件菜单组件 MenuComponent列表组件 ExtTelListComponent状态组件 ExtTelStatusComponent父组件界面主体MainIndex 实现功能:在 MainIndex中引入三个子组件 通过点击 菜单组件切换加载 列表组件和状态组件 实现效果一、菜单组件 MenuComponent<......
  • 案例-业务接口执行效率
         第一个*为返回值表示可以设置所有返回值类型,第二个*Service表示前面这个包下的所有以Service结尾的接口,第三个*表示接口里的所有方法,(..)表达为可以设置所有参数类型也可以不设置参数......
  • Linux curl测试服务器接口请求
    一、背景获取公众号token接口:https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET为向小程序推送公众号消息,需先调用微信接口获取公众号token,而调用该接口需要添加IP白名单,所以这里需要一种方式来获取调用接口所在服务......