I've only been working with Django for a few weeks, and just learned deployment. I have an AWS EC2 Instance, which I'm able to deploy my Django website/app to (i.e., if I go to the IP address in my browser, I'm able to access my website). However, I can't figure out how to deploy that same website to my domain name, which is registered on AWS.
I followed AWS's documentation (http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-ec2-instance.html), and https://cachecheck.opendns.com/ shows that my domain name routes to my EC2 instance. However, when I go to my domain name in my browser, it shows a 400 Bad Request. Is there something else I need to do when I setup nginx or gunicorn? I've tried replacing the {{yourEC2.public.ip}}
in the nginx code to be my domain name instead of the IP address.
I haven't been able to find any other resources online regarding deployment to domain names, specifically with AWS.
This is what I have for deploying to the EC2 instance:
settings.py
:
DEBUG = False
ALLOWED_HOSTS = ['{{yourEC2.public.ip}}']
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
(venv) ubuntu@54.162.31.253:~myRepoName$ python manage.py collectstatic
gunicorn
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/{{repoName}}
ExecStart=/home/ubuntu/{{repoName}}/venv/bin/gunicorn --workers 3 --bind
unix:/home/ubuntu/{{repoName}}/{{projectName}}.sock
{{projectName}}.wsgi:application
[Install]
WantedBy=multi-user.target
nginx:
server {
listen 80;
server_name {{yourEC2.public.ip}};
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/{{myRepoName}};
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/{{myRepoName}}/{{projectName}}.sock;
}
}