Question 1
As I know, django has ALLOWED_HOSTS option in settings.py to prevent from spoofing attacks.
However, I don't know which one is the most proper value for ALLOWED_HOSTS among case 1~3. (Or all of them make same result?)
Case 1 : ALLOWED_HOSTS = ['.mydomain.com']
Case 2 : ALLOWED_HOSTS = ['myipaddress']
Case 3 : ALLOWED_HOSTS = ['.mydomain.com', 'myipaddress']
This question is quite related with previous([1], [2], [3]) questions, but I couldn't make a decision clearly.
Question 2
According to Brent's answer, editing nginx's configuration could yield same result. (See following codes)
upstream app_server {
server unix:/tmp/gunicorn_mydomain.com.sock fail_timeout=0;
}
server {
...
## Deny illegal Host headers
if ($host !~* ^(mydomain.com|www.mydomain.com)$ ) {
return 444;
}
location / {
proxy_pass http://app_server;
...
}
}
Like similar logic first question, what would be the best value to replace mydomain.com|www.mydomain.com
?