我是自耕农的新手,正试图让一个基本的自耕农生成的angularjs网站部署到弹性豆茎上。在我部署的那一刻,我收到了502:Bad Gateway。我可以使用像
这样的东西将一个简单的nodejs应用程序部署到awsserver.js
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(process.env.PORT || 8888);
如果没有在网址中指定端口,此页面可以正常工作。不确定这是否与此问题相关。
使用yeoman角度发生器的过程非常标准,即
yo angular
yo angular:controller testController
..add some directives / views etc..
grunt server -- serves up pages correctly on port 9000
grunt -- which creates the dist folder
在这个阶段,我在本地有一个工作的angularjs应用程序,从这里我遵循正确部署早期hello world示例的相同工作流程(提交到git repo,使用弹性beanstalk cli..etc提供图像..)。我根据/ dist文件夹的内容创建了一个repo,并在我获得502 ..
的地方部署了它我在这里有2个线索,首先我应该在80端口上听 - 虽然我之前的样本:8888工作,所以我认为下一个要求是最相关的,这是 根目录中名为server.js的文件。
grunt构建输出\ dist包含:
bower_components
views
styles
scripts
25e920e4.modules.js
5e188624.scripts.js
76c21dca.plugins.js
所以我不确定下一步。我注意到app.js不是dist输出的一部分,但现在我有这3个新的脚本js文件。我需要配置什么才能使nodejs容器提供这个新结构?
这是原始的app.js
'use strict';
angular.module('nodealphaApp', [])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
});
如果我能提供更多信息,请告诉我
干杯!
答案 0 :(得分:1)
我有同样的问题!他们真的希望您使用grunt buildcontrol
,但AWS没有选项。 grunt buildcontrol
推送到远程,这不是Elastic Beanstalk部署的方式。
当您键入eb deploy
时,它将部署.git目录中的所有内容,而不仅仅是dist/
目录。我的解决方法是在dist/
内创建一个本地git存储库。
cd dist/
终端。git init
以创建本地git repo。dist/
一直是.gitignore-d。eb init
内正常运行eb create
,eb deploy
,dist/
。eb open
,双手交叉。答案 1 :(得分:0)
以下是Angular Nodejs模板的示例:https://github.com/joshdmiller/ng-boilerplate
如果端口匹配,也许你应该检查Grunt的配置文件。在您的Gruntfile.js中,您将拥有端口9000,并且在Nodejs代码中您正在监听8888.因此,请更改其中一个,以便它们具有相同的端口。
看看:
grunt.registerTask('server', function (target) {
它将运行一些任务,并且在其中一个任务中(可能是“打开”)将使用Grunt配置中的端口号。参见
grunt.initConfig({ ...
我希望这会对你有所帮助。