nginx.conf里面的:

server {
listen 80 default_server;
server_name localhost;
root /var/www/html/dist;

location / {
root /var/www/html/dist;
try_files $uri $uri/ @router
index index.html;
}

location $router {
rewrite ^.*$ /index.html last;
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

 

/*

注意:

1)vue生成的dist目录放在/var/www/html下,如果放到/root/下的话,就会因为权限问题而nginx 403 forbidden

2) axios里的 base里面写的服务端api的地址如localhost、127.0.0.1等换成服务器http://ip