以win為例:下載nginx霜幼,解壓饶囚。然后在解壓目錄(有nginx.exe的目錄)地址欄輸入cmd棕所,打開(kāi)cmd窗口
啟動(dòng)nginx
start nginx
重啟nginx
nginx -s reload
修改conf文件夾中的nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root dist;#這里存放的是你根目錄的網(wǎng)站文件唬格,可以不用管
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /admin {
alias 你新打包的帶二級(jí)目錄的dist文件夾;
try_files $uri $uri/ /admin/index.html;#這里要加上你的二級(jí)目錄名稱
index index.html index.htm;
}
location /prod-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
若依vue修改:
1:修改router/index.js
export default new Router({
base:'admin',//添加二級(jí)目錄的名稱
mode: 'history', // 去掉url中的#
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
2:修改vue.config鹃操。添加admin二級(jí)目錄名稱
publicPath: process.env.NODE_ENV === "production" ? "/admin/" : "/admin/",
3:修改loginout.vue
在跳轉(zhuǎn)前面加上admin
4:在public文件夾里面的所有路徑都要加 ./