简体   繁体   English

Web 资源不会加载到 Beanstalk - https 而不是 http 标头

[英]web ressources don't load on Beanstalk - https instead of http header

Issue问题

So i created a simple http web server with node.js and express (mostly its just the skeleton from the express application generator).所以我用 node.js 和 express(主要是 express 应用程序生成器的框架)创建了一个简单的 http web 服务器。 Then i uploaded the server to an AWS Beanstalk web environment.然后我将服务器上传到 AWS Beanstalk Web 环境。

The issue is that i can't load the ressources (CSS and javascript) from the server if i connect to it.问题是我无法从服务器加载资源(CSS 和 javascript),如果我连接到它。 i get a net::ERR_CONNECTION_TIMED_OUT for loading all ressources if i open the site in my browser.如果我在浏览器中打开网站,我会得到一个net::ERR_CONNECTION_TIMED_OUT来加载所有资源。

I assume the issue is that the get request on beanstalk uses a "https" url,我认为问题是 beanstalk 上的 get 请求使用了“https”网址,

Request URL: https://...elasticbeanstalk.com/javascripts/GameLogic.js

Because it works on my localhost but there it uses a "http" url.因为它适用于我的本地主机,但它使用“http”网址。

Request URL: http://localhost:3000/javascripts/GameLogic.js

Also the html site itself loads (after the timeout of the ressources) but this also uses a "http" request html 站点本身也会加载(在资源超时之后),但这也使用“http”请求

Request URL: http://....elasticbeanstalk.com/

can you change the header request url (for CSS, JS) in AWS Beanstalk Web-Environment to use http instead of https?您能否更改 AWS Beanstalk Web-Environment 中的标头请求 url(用于 CSS、JS)以使用 http 而不是 https? Or change it in HTML or on Node.js?或者在 HTML 或 Node.js 上更改它?

info信息

The server uses the node.js helmet module.服务器使用 node.js 头盔模块。 Then i just send my html page on incoming requests:然后我就传入请求发送我的 html 页面:

app.get('/', function(req, res, next) {
res.sendFile(path.join(__dirname + "/public/main.html")); //Um bei / als pfad die main.html zu geben
}); 

In the html page i request the ressources:在 html 页面中,我请求资源:

<link rel="stylesheet" type="text/css" href="\stylesheets\style.css">
<script src="/javascripts/jquery.min.js"></script>
<script src="/javascripts/GameLogic.js"></script>

solution attempts解决方案尝试

I have tried not using helmet, but that version behaves exactly the same and doesn't load ressource if it is on beanstalk (on localhost server it always worked).我试过不使用头盔,但该版本的行为完全相同,并且如果它在 beanstalk 上(在 localhost 服务器上它始终有效),则不会加载资源。

I also tried chaning some security group rules to allow https on port 443 from all sources to the loadbalancer and https on port 443 from the loadbalancer to the ec2 instance.我还尝试更改一些安全组规则,以允许从所有来源到负载均衡器的端口 443 上的 https 和从负载均衡器到 ec2 实例的端口 443 上的 https。 Situation didn't change.情况没有改变。

then i tried redirecting https requests to http然后我尝试将 https 请求重定向到 http

app.get('/', function(req, res, next){
    console.log("redirect to http?");
    res.redirect('http://' + req.headers.host + req.url);
});

But then the site doesn't even load the html because of "to many redirects".但是由于“多次重定向”,该站点甚至没有加载 html。

So currently im out of ideas on how to make the https request work or how to change it to an http request.所以目前我不知道如何使 https 请求工作或如何将其更改为 http 请求。

note笔记

I am also using a student account so i have no rights to use the AWS Certificate Manager or redirect ELBs to HTTPS, if that has anything to do with it.我也在使用学生账户,所以我无权使用 AWS 证书管理器或将 ELB 重定向到 HTTPS,如果这与它有关的话。

OK it was the helmet module for node.js at fault.好吧,是 node.js 的头盔模块出了问题。 I dont undertand it good enough to say what exactly changed the headers to https, hsts seems to be only part of it.我不太明白到底是什么将标题更改为 https,hsts 似乎只是其中的一部分。

But after completly removed it, i and other people could access the web app and load the ressources.但是在完全删除它之后,我和其他人可以访问网络应用程序并加载资源。

The reason why i didn`t catch it earlier in my tests: I never deleted or regenerated my package-lock after removing helmet.我在测试中没有更早发现它的原因:我在取下头盔后从未删除或重新生成我的包裹锁。 So it was still in there.所以它还在那里。 Now i uninstalled it and made a new package-lock before uploading to AWS Beanstalk.现在我卸载了它并在上传到 AWS Beanstalk 之前创建了一个新的包锁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM