Trying to deploy django app to AWS EC2 instance using Gunicorn and Nginx

0 votes

I'm trying to deploy a Django app on AWS EC2 and also using gunicorn and Nginx in the process, I followed this tutorial link. I'm not sure what is going wrong, this is the first time I've used AWS EC2, when I try to launch the IP address of the instance it comes back as:

"can't open the page because Safari can't establish a secure connection to the server".

In my AWS console the EC2 'instance state' shows it's running.

It has been set up in ubuntu 18.04, I've also set up security groups in my EC2 instance with HTTP, HTTPS, 443, 80, 8000, 5432, and 22 all allowed from any IP address except the 22 which only has my IP address as access. Also in my Django app settings 'ALLOWED_HOSTS', I've added the instance IP address and also '*'.

this is my gunicorn.socket file:

[Unit]

Description=gunicorn socket

[Socket]

ListenStream=/run/gunicorn.sock

[Install]

WantedBy=sockets.target

and my gunicorn service file:

[Unit]

Description=gunicorn daemon

Requires=gunicorn.socket

After=network.target

[Service]

User=djangoadmin

Group=www-data

WorkingDirectory=/home/ubuntu/djangoapp1 /

ExecStart=/home/djangoadmin/pyapps/venv/bin/gunicorn \

--access-logfile - \

--workers 3 \

--bind unix:/run/gunicorn.sock \

djangoapp1.wsgi:application

[Install]

WantedBy=multi-user.target

ngnix conf file :

server {

listen 80;

listen 443;

server_name **.***.***.*;

location = /favicon.ico { access_log off; log_not_found off; }

location /static/ {

root /home/ubuntu/djangoapp1;

}

location /media/ {

root /home/ubuntu/djangoapp1;    

}

location / {

include proxy_params;

proxy_pass http://unix:/run/gunicorn.sock;

}

}

I check the gunicorn socket with :

sudo systemctl start gunicorn.socket

sudo systemctl enable gunicorn.socket

sudo systemctl status gunicorn.socket

and it shows it running fine

I've also created a nginx conf file :

sudo vim /etc/nginx/sites-available/djangoapp1

and linked it with :

sudo ln -s /etc/nginx/sites-available/djangoapp1 /etc/nginx/sites-enabled

then restarted the nginx server:

sudo systemctl restart nginx

Still, nothing works! would appreciate any help.

Apr 4, 2022 in Others by Kichu
• 19,050 points
1,365 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

Trying to import a CSV file and convert it into a table using VBA

You cannot convert a range that contains ...READ MORE

answered Apr 10, 2023 in Others by Kithuzzz
• 38,010 points
1,372 views
0 votes
1 answer

How to create subnet inside a VPC in AWS using Terraform?

Hi@akhtar, You need to use aws_subnet resource inside your ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,440 points
446 views
0 votes
1 answer

How to create a App using Material Design?

Hi@akhtar, You need to use the MaterialApp method ...READ MORE

answered Jul 23, 2020 in Others by MD
• 95,440 points
431 views
0 votes
1 answer

How to deploy card banners in flutter app?

Hi, If you are trying to create a ...READ MORE

answered Sep 2, 2020 in Others by MD
• 95,440 points
1,019 views
0 votes
1 answer

Avoid killing children when parent process is killed

I would recommend against your design as ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,090 points
5,334 views
0 votes
1 answer

Avoid killing children when parent process is killed

I would recommend against your design as ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,090 points
558 views
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP