Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk Nginx Serve Static Files

I am new to Elastic Beanstalk, trying to serve a Node.js Express app and utilize serving our static files separately with Nginx. None of the tutorials I've come across are explicit in how to define the virtual path.

I'm attempting to do this through the AWS console in the browser. I am trying to add a virtual path/directory setup for the static files. In the console I'm at
Elastic Beanstalk > myapp > configuration > Static Files

Elastic Beanstalk console

But no matter what I add here I get this error message: enter image description here

I've also tried adding the full directory path (/var/app/current/dist/public/images/). Is there another .ebextensions/*.conf file I need to add? I don't have a lot of experience with Nginx so if the fix is a .conf file I wouldn't know what it is

like image 952
Jeremy Avatar asked Dec 05 '17 05:12

Jeremy


People also ask

How do I add static files to Elastic Beanstalk?

Configure static files using the consoleIn the navigation pane, choose Configuration. In the Software configuration category, choose Edit. In the Static files section, enter a path for serving static files and the directory of the static files to serve into the empty row at the bottom of the list.

Does Elastic Beanstalk use nginx?

Elastic Beanstalk uses nginx as the reverse proxy to map your application to your Elastic Load Balancing load balancer on port 80. Elastic Beanstalk provides a default nginx configuration that you can either extend or override completely with your own configuration.

What is proxy server in Elastic Beanstalk?

Elastic Beanstalk provides a default proxy configuration that you can either extend or completely override with your own configuration. By default, Elastic Beanstalk configures the proxy to forward requests to your application on port 5000.

What is Wsgipath?

WSGI Path – The name of or path to your main application file. For example, application.py , or django/wsgi.py . NumProcesses – The number of processes to run on each application instance. NumThreads – The number of threads to run in each process.


2 Answers

This is a known bug, They only support python when it comes to the web console. if your application is in nodejs you would need to set these properties from the cli.

you can setup the values from cli this way

aws elasticbeanstalk update-environment --environment-id your_enviornment_id --option-settings 'Namespace=aws:elasticbeanstalk:container:nodejs:staticfiles,OptionName=/assets,Value=/static/assets'

or editing the config file from eb config.

like image 156
Kashif Zaidi Avatar answered Sep 21 '22 08:09

Kashif Zaidi


Kashif Zaidi's answer works well, but if you want to keep the setting consistent across multiple deployments, you can make a .ebextensions directory at the project root with some file like 01_environment_settings.config that specifies that setting like so:

option_settings:
  aws:elasticbeanstalk:container:nodejs:staticfiles:
    "/assets": "/static/assets"

You can specify multiple static file settings, for example:

option_settings:
  aws:elasticbeanstalk:container:nodejs:staticfiles:
    "/app/": "frontend_build/"
    "/static/": "frontend_build/static/"
    "/backend_static": "static/"
like image 42
Nick Merrill Avatar answered Sep 19 '22 08:09

Nick Merrill