Elastic Beanstalk Node Static Files are not Loaded


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:

    /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?
asked a year ago174 views
1 Answer

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.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions