amazon-web-services - 如何在 AWS 上运行 Vue JS 应用程序?

标签 amazon-web-services vue.js amazon-ec2

dummy_prototype_1 是一个简单的 Vue JS 应用程序,它在我的本地机器上运行良好。现在,我将我的应用程序上传到 AWS EC2。我想在永久 URL http://3.137.154.536:8000/ 上运行它。但是,以下代码在本地主机 http://localhost:8080/ 上运行服务器。如何在我的永久 URL 上运行它?我错过了什么吗?让我知道是否需要任何进一步的信息。我是 AWS 的新手,请帮助我。

ubuntu@ip-172-31-43-235:~$ ls
Codes
ubuntu@ip-172-31-43-235:~$ cd Codes
ubuntu@ip-172-31-43-235:~/Codes$ ls
dummy_backend_1  dummy_prototype_1  nodeserver_1
ubuntu@ip-172-31-43-235:~/Codes$ cd dummy_prototype_1/
ubuntu@ip-172-31-43-235:~/Codes/dummy_prototype_1$ npm run dev

> proto@1.0.0 dev /home/ubuntu/Codes/dummy_prototype_1
> cross-env NODE_ENV=development webpack-dev-server --open --hot

Project is running at http://localhost:8080/
webpack output is served from /dist/
404s will fallback to /index.html
Unable to open browser. If you are running in a headless environment, please do not use the open flag.
{ parser: "babylon" } is deprecated; we now treat it as { parser: "babel" }.

这里是 package.json:

{
  "name": "proto",
  "description": "Prototype",
  "version": "1.0.0",
  "author": "Jason",
  "license": "MIT",
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  },
  "dependencies": {
    "@melmacaluso/vue-modal": "^2.1.0",
    "firebase": "^7.14.2",
    "fusioncharts": "^3.15.1-sr.1",
    "vue": "^2.5.11",
    "vue-fusioncharts": "^3.0.4",
    "vue-router": "^3.1.6",
    "vuex": "^3.3.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ],
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.0",
    "babel-preset-stage-3": "^6.24.1",
    "cross-env": "^5.0.5",
    "css-loader": "^0.28.7",
    "file-loader": "^1.1.4",
    "vue-loader": "^13.0.5",
    "vue-template-compiler": "^2.4.4",
    "webpack": "^3.6.0",
    "webpack-dev-server": "^2.9.1"
  }
}

最佳答案

如果您计划在 EC2 实例上托管 SPA,则需要像 Apache 这样的 HTTP 服务器。

  1. 关注this guide在 EC2 上安装 apache

  2. 在您的本地系统中,构建您的 vue 项目。

    npm run build
    
  3. dist/ 文件夹将在项目根目录下生成。

  4. dist/ 的内容上传到您的 EC2 实例上的 /var/www/html

[编辑] 为 apache 添加历史模式支持配置。

对于历史记录模式,您需要像这样配置服务器:

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

从这里post .

[编辑] 上传 dist 到 EC2 实例

从您的项目根目录,运行以下命令。

scp -i /path/to/ec2key.pem -r dist/ ubuntu@ip-172-31-43-235:/var/www/html

[编辑] 重启 Apache2 服务器

sudo service apache2 restart

关于amazon-web-services - 如何在 AWS 上运行 Vue JS 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63784375/

相关文章:

amazon-web-services - AWS - 将 EC2 扩展到更大的类型(示例 : micro -> large)

python - Ubuntu 14.04 : command not found 中的 AWS Elastic Beanstalk (eb) 安装

curl - AWS 身份验证需要有效的 Date 或 x-amz-date header curl

typescript - 异步函数的返回类型必须是全局 Promise<T> 类型

function - 如何使用 vue.js 在 @click 事件上添加两个方法?

java - 获取 EC2 实例中每个资源更改的通知

amazon-web-services - 如何以编程方式获取亚马逊上销售排名前 100 的商品?

json - 在云形成中如何将可信实体与 IAM 角色的身份提供商相关联

Javascript/Vue3 - Mixins - 默认返回 'null'

mysql - AWS EC2 mysql root密码问题