nginx 配置, 一个nginx 配置多个项目
user root; # 这个默认是nginx用户 要改 否则还要给文件夹分权限
server {
listen 9000;
server_name localhost;
location /vue-page/ {
alias /home/vue-page/;
index index.html;
try_files $uri $uri/ /vue-page/index.html;
}
location ^~/java-server/ {
proxy_pass http://127.0.0.1:8080;
proxy_redirect http://127.0.0.1 http://127.0.0.1:8080;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 1000m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
vue-page 是vue的根路径
vue的配置
vue.config.js
module.exports = {
/**
* You will need to set publicPath if you plan to deploy your site under a sub path,
* for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
* then publicPath should be set to "/bar/".
* In most cases please use '/' !!!
* Detail: https://cli.vuejs.org/config/#publicpath
*/
publicPath: process.env.NODE_ENV === 'production' ? '/vue-page/' : '/',
}
.env.production
VUE_APP_BASE_API = '/gbxt'
java-server 是后端 springboot 的context-path
server.servlet.context-path=/gbxt