vue项目部署到Ubuntu下apache2

开发软件:HbuilderX
用finallshell操作Ubuntu下apache2

一、vue项目文件配置与打包

1、修改config文件夹下index.js文件
在这里插入图片描述
在这里插入图片描述

 "/api": {
              "target": "http://140.143.242.103", //finallshell服务器的ip地址
              "changeOrigin": true,
      }

2、在HbuilderX终端上运行npm run build打包构建,运行完成后会多一个dist文件夹,文件夹下的内容即要上传到服务器的内容。

在这里插入图片描述

二、代码部署到Ubuntu下apache2

前台代码放在/var/www/html文件下
1、打开finallshell连接服务器,进入/var/www/html,将本地dist文件夹下static文件和index.html文件拖动上传到该目录下。
在这里插入图片描述
2、添加.htaccess文件
在这里插入图片描述
双击打开文件,文件中添加如下代码,添加后Ctrl+S保存

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

3、修改/etc/apache2下apache2.conf文件,将AllowOverride None改为AllowOverride All

在这里插入图片描述
4、重启apache2即可,重启命令如下:

# /etc/init.d/apache2 restart

Linux系统为Ubuntu

一、Start Apache 2 Server /启动apache服务
#/etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start
二、 Restart Apache 2 Server /重启apache服务
#/etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart
三、Stop Apache 2 Server /停止apache服务
/etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop

发布了17 篇原创文章 · 获赞 1 · 访问量 2194

猜你喜欢

转载自blog.csdn.net/qq_41512822/article/details/103905629