Nginx
Nginx
2025-04-09 11:48
阅读:79
评论:0
Nginx 配置vue项目
nginx 前缀转发 报错 vue Uncaught SyntaxError: Unexpected token '<' 或css 出现 404 配置以下内容即可 nginx 配置 server { listen 80; servername yourdomain.com; location /ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
worker_processes 1; events { worker_connections 1024; } http { # 必须要导入不然样式nginx加载不出来样式 include mime.types; # 必须要导入不然样式nginx加载不出来样式 default_type application/octet-stream; # sendfile on; # keepalive_timeout 65; server { listen 1100; server_name localhost; # vue 存放位置 root /usr/vuejs/nginx; # 指定首页 index index.html; # 以下配置是防止刷新页面404。例如进入 http://localhost/test/index 页面。刷新页面出现404.加上下面到代码即可解决 location / { try_files $uri $uri/ @router; index index.html; } location @router { rewrite ^.*$ /index.html last; } } }nginx 前缀转发
-
报错 vue Uncaught SyntaxError: Unexpected token '<' 或css 出现 404
-
配置以下内容即可
nginx 配置 server { listen 80; server_name your_domain.com;
location /backend-management/ { alias /path/to/your/vue/app/backend-management/; # 必须知道项目路径 try_files $uri $uri/ /backend-management/index.html; # 或者 try_files $uri $uri/ /index.html; }}
vue项目重vue.config.js 配置 module.exports = { publicPath: process.env.NODE_ENV === 'production'? '/backend-management/' : '/' }