Elastic Beanstalk Node Static Files are not Loaded

0

I am having trouble serving my static files on Elastic Beanstalk using NodeJS deployed on Linux 2. My local environment works, but my deployment is unable to serve the static files located in a top-level static folder called 'public'.

My configuration is as follows:

option_settings:
  aws:elasticbeanstalk:environment:proxy:staticfiles:
    /images: public/images
    /javascripts: public/javascripts
    /stylesheets: public/stylesheets

I am certain that the configuration is processed correctly because I can view the results of the static file configuration within AWS UI. When I navigate to the home directory of my site (using http:// protocol), the HTML page is loaded, but the CSS and JS under the public directory is not. The error I get is as follows:

GET https://<domain name>/stylesheets/layout.css net::ERR_CONNECTION_TIMED_OUT

Note that the https:// protocol is used. From my understanding, the reason my local environment works is that my application serves the static files with the correct protocol. Here are my questions:

  1. Why are my static files being served with protocol https:// when I request my home directory using http://?
  2. I don't want to serve my static files through the application to reduce the number of requests to my application, noted here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-environmentproxystaticfiles. Is there anything actually wrong with the configuration?
已提问 2 年前201 查看次数
1 回答
0

Issue was resolved. I am using Helmet JS for Content Security Policy (CSP), and it has a directive for converting insecure requests to secure ones: 'upgrade-insecure-requests'. Make sure to remove that in the development phase for a site that is relying on http:// for content. Best practice is to use https:// when possible.

已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则