【问题标题】:Is it possible to push a index.html to heroku?是否可以将 index.html 推送到heroku?
【发布时间】:2014-06-27 04:29:18
【问题描述】:

我使用名为 index.html 的索引文件开发了一个纯前端应用程序。每次我推送到heroku,我都需要将它重命名为index.php,以便告诉heroku 使用php。有没有另一种方法来声明我想要什么类型的服务器?这样我就可以将我的文件保存为 html 文件?

【问题讨论】:

  • 您不能直接提供静态文件,但您可以通过简单的 node.js 应用程序来管理它。看我的回答here

标签: php html heroku


【解决方案1】:

您也可以将一个空的composer.json 放入您的项目中,以使 Heroku 将您的项目视为 PHP 项目。

index.php 优于 index.html 的偏好来自 Apache 在 Heroku 上使用的默认 DirectoryIndex 指令;它与您的浏览器无关。要更改它,您可以将带有DirectoryIndex index.html 的.htaccess 拖放到您的应用程序中。

如果您只想要静态网站的原始性能,那么使用 Nginx 也可能是一个好主意。默认配置对于您的目的应该是合理的,因此在您的项目中添加一个 Procfile 和 web: vendor/bin/heroku-php-nginx 以及一个空的 composer.json(并且没有 index.php),您就可以开始了。

另请参阅https://devcenter.heroku.com/articles/php-support 和https://devcenter.heroku.com/articles/custom-php-settings 了解更多详情。

【讨论】:

    【解决方案2】:

    添加一个名为 index.php 的空文件,这将被 heroku 使用,但是 index.html 将被浏览器优先考虑。

    【讨论】:

      【解决方案3】:

      您可以使用ExpressJS 来完成这个简单的node.js 应用程序;

      假设您的项目文件夹有一个名为 public 的子文件夹,

      var express = require('express');
      var app = express();
      app.use('/', express.static(__dirname + '/public'));
      var port = Number(process.env.PORT || 5000);
      app.listen(port, function() { 
          console.log('Your files will be served through this web server')
      });
      

      将此代码保存在app.js中,将你的静态文件放在public文件夹下,并准备你的Procfile

      最终的文件夹结构将是;

      yourproject
      --public/
      ----your staticfiles
      --app.js
      --Procfile
      

      Procfile 将是;

      web: node app.js
      

      然后部署您的项目。当您请求静态文件时,例如; .../index.html, index.html 将在公共文件夹下提供

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-10
        • 1970-01-01
        • 2014-02-13
        • 1970-01-01
        • 2019-03-19
        • 2010-12-05
        • 2021-08-25
        相关资源
        最近更新 更多