1.打包vue项目上传到服务器目录 /home/dhwww
没有权限,可以先上传到当前用户目录下,再copy到dhwww文件夹
2.安装Nginx
sudo apt-get install nginx
3.配置Nginx
3.1 查看Nginx目录:
root@VM-4-11-ubuntu:/home# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
3.2 配置
cd /etc/nginx/sites-enabled
vim default
server_name localhost;
root /home/dhwwww/dist;
# Add index.php to the list if you are using PHP
index index.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ @router; # 指向下面的 @router否则会出现 404
}
location @router {
rewrite ^.*$ /index.html last;
}
4.重启Nginx
nginx -s reload
5.访问外网地址