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

原文链接: https://www.cnblogs.com/XiaoMing98/p/14875211.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

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

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/211350

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 上午12:45
下一篇 2023年2月13日 上午12:46

相关推荐