前端配置
vue 配置后台地址
/public/config.json
1 2 3
| { "serverUrl": "http://localhost:8080" }
|
main.js
1 2 3 4 5 6
| import axios from "axios";
axios.get("/config.json").then((res) => { app.config.globalProperties.$config = res.data; }); export const globals = app.config.globalProperties;
|
request.js
1 2 3 4 5 6 7
| import { globals } from "@/main"; import axios from "axios"; const serverUrl = globals.$config?.serverUrl || "http://localhost:8080"; const request = axios.create({ baseURL: serverUrl, timeout: 30000, });
|
如果有跨域问题,则可以在 vite.config.js 中引入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| import { defineConfig, loadEnv } from "vite"; const serverUrl = globals.$config?.serverUrl || "http://localhost:8080"; export default ({ mode }) => defineConfig({ server: { proxy: { "/api": { target: loadEnv(mode, process.cwd()).VITE_APP_URL, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ""), }, }, }, });
|
然后在.env.development 和.env.production 中写好环境变量
1 2
| # dev.development VITE_APP_URL="http://localhost:8080"
|
1 2
| # dev.production VITE_APP_URL="http://114.55.132.144:8080"
|
vue 打包:npm run build
后端配置
给服务器安全组添加 8888 端口规则
这里以阿里云为例
安装宝塔
1
| yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec
|
然后用打开显示的外网 ip 并用账号密码登陆
本地配置
springboot 打包:mvn clean package
Xshell (命令)和 Xftp (上传文件)
ifconfig 命令可以查看内网 ip,配置 application-prod.yml 的数据库 url
1 2 3 4 5 6 7 8 9 10 11 12
| spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://172.27.133.111:3306/big_event username: root password: data: redis: host: localhost port: 6379 server: port: 8080
|
常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| netstat -nlp | grep 8085
kill -9 372027
tail -f server.log
cd /home/big-event nohup java -jar big-event-0.0.1-SNAPSHOT.jar > server.log 2>&1 &
echo "nohup java -jar big-event-0.0.1-SNAPSHOT.jar > server.log 2>&1 &" > start.sh
chmod 770 start.sh
./start.sh
|
服务器配置
安装 nginx
1 2 3 4 5 6 7 8
| yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
|
进入 tmp
1 2 3
| cd /tmp/ wget http://nginx.org/download/nginx-1.24.0.tar.gz tar -zxvf nginx-1.24.0.tar.gz
|
解压
1 2 3 4 5 6 7 8 9 10 11 12
| cd /usr/local mkdir nginx cd nginx
cp -R /tmp/nginx-1.24.0 ./
cd nginx-1.24.0
./configure --with-http_stub_status_module --with-http_ssl_module
make && make install
|
进入 nginx
1 2 3 4 5 6 7
| cd /usr/local/nginx-1.24.0/sbin ./nginx
./nginx -s stop ./nginx -s start ./nginx -s reload
|
编辑/usr/local/nginx/conf/nginx.conf,使得 root 指向前端文件所在目录
1 2 3 4 5 6
| cd .. cd conf vi nginx.conf
|
1 2 3 4 5 6 7 8 9 10 11 12
| server { listen 80; server_name localhost;
location / { root /home/big-event/dist; index index.html index.htm; }
|
然后
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| cd .. cd sbin/ ./nginx -s reload
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
netstat -ntlp|grep 80
fuser -k 80/tcp
cd /usr/local/nginx/sbin ./nginx
|
redis
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| cd /usr/local/redis-6.0.8/src
redis-cli shutdown
redis-server redis.conf
ps -ef|grep redis
netstat -ntlp|grep 6379
./redis-server /etc/redis.conf
./redis-server /usr/local/redis-6.0.8/redis.conf
|
重启服务器
1 2 3 4 5
| cd /home/big-event
./start.sh
cd /usr/local/nginx/sbin
|