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

要在 CentOS 9 上配置 Apache 2 并部署 Vue 项目,您需要按照以下步骤进行操作: 1. 安装 Apache 2: ``` sudo dnf install httpd ``` 2. 启动 Apache 服务并设置开机自启动: ``` sudo systemctl start httpd sudo systemctl enable httpd ``` 3. 配置防火墙允许 HTTP 流量通过: ``` sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload ``` 4. 在 Apache 配置中创建一个虚拟主机文件来指向您的 Vue 项目。假设您的项目位于 `/var/www/html/my-vue-app` 目录下,创建一个名为 `my-vue-app.conf` 的虚拟主机配置文件: ``` sudo nano /etc/httpd/conf.d/my-vue-app.conf ``` 5. 在 `my-vue-app.conf` 文件中添加以下内容: ```apache <VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot "/var/www/html/my-vue-app/dist" ServerName your-domain.com <Directory "/var/www/html/my-vue-app/dist"> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> ErrorLog /var/log/httpd/my-vue-app-error.log CustomLog /var/log/httpd/my-vue-app-access.log combined </VirtualHost> ``` 确保将 `your-domain.com` 替换为您的域名或服务器 IP 地址。 6. 保存并关闭文件。 7. 重新加载 Apache 配置: ``` sudo systemctl reload httpd ``` 8. 现在,您的 Vue 项目应该已经部署在 Apache 2 上了。您可以通过访问服务器的 IP 地址或域名来查看您的 Vue 应用程序。 请注意,以上步骤假设您的 Vue 项目已经构建并生成了静态文件,将这些文件放在 `/var/www/html/my-vue-app/dist` 目录下。如果您的项目尚未构建,请先进行构建,然后将生成的文件放置在适当的目录中。 希望这可以帮助到您!如有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值