Background:
Current setup is
- Have a website hosted in AWS S3 (e.g. app.com)
- Have api server hosted in elastic beanstalk (e.g. api.com)
- Website makes api requests to api server
ALLOWED_HOST has been set in Django so that it includes
- The elastic beanstalk address
- The url for the api
Issues:
- The web app is working fine. However, I am seeing numerous requests to the api from random urls (bots, exploits, etc). This is firing off hundreds of
Invalid HTTP_HOST header
errors. I could obviously turn off the error notification, but that does not feel right. - The log suggests adding bunch of ip addresses to the ALLOWED_HOST, most of which is the ip address of my load balancer. However, as my regular api requests are going through without problem, I doubt adding the IP address of load balancer to ALLOWED_HOST is the solution either.
- So that would leave changing the load balancer itself so that it does not direct requests to Django if it is invalid. I have found a few answer with regards to this such as
Two questions:
- Is the above modification the correct way to handle this problem?
- Is there a way to apply this programmatically to Elastic Beanstalk environment?
Will appreciate any help
Thank you!