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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南