前后端简单部署

前后端简单部署

1.下载java

https://www.oracle.com/java/technologies/downloads/#java8

改环境变量

2.安装mysql8.0

https://dev.mysql.com/downloads/installer/
记得安装地址 安装到 C:\Program Files\MySQL\MySQL Server8.0


‘’

配置环境变量

找到path

mysql-u root-p

3.创建数据库和表

自己的数据库创建的代码

4.启动后端

java-jar quiz-backend.jar

5.启动前端

下载nginx,启动前端

https://nginx.org/en/download.html

打开C:\nginx\conf\nginx.conf,找到server部分,修改为:

server{listen80;server_name localhost;# 前端静态文件location /{root C:\quiz-system\frontend;index index.html;try_files$uri$uri/ /index.html;}# API反向代理到后端location /api{proxy_pass http://127.0.0.1:8080;proxy_set_header Host$host;proxy_set_header X-Real-IP$remote_addr;}}

启动nginx

cdC:\nginx start nginx

直接用源码启动前端

npminstallnpmrun dev

改vite.config文件内容,添加允许的host

import{defineConfig}from'vite'importvuefrom'@vitejs/plugin-vue'exportdefaultdefineConfig({plugins:[vue()],server:{host:'0.0.0.0',port:3000,allowedHosts:['域名网址','localhost','127.0.0.1'],proxy:{'/api':{target:'http://127.0.0.1:8080',changeOrigin:true}}}})

7.打开网址

1.解析域名
2.放通防火墙规则
端口填写前端的端口