vue项目打包,并部署在Nginx上

1.打包准备工作

修改:vue.config文件
将 publicPath: '/', 改为publicPath: './'
修改router文件
将 mode: 'history' 注释
执行 npm run build
完成之后生成dist文件夹,复制该文件夹到Linux中

2.部署在Linux中Nginx服务器上

配置Nginx源

vim /etc/yum.repos.d/nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

执行

yum makecache

安装依赖

yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

安装Nginx

yum install nginx

配置Nginx环境

cd /etc/nginx/conf.d
vi default.conf 修改端口号,以及项目所在地址

server {
listen       8080;    //端口地址
server_name  localhost;

#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;

location / {
    root   /opt/dist;    //项目文件
    index  index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}

启动Nginx

systemctl start nginx
posted @ 2021-06-11 15:17  此用户很低调没有昵称  阅读(624)  评论(0)    收藏  举报