0

Hi so I am trying to deploy my portfolio to Ubuntu Server 16.04 but I keep getting internal server error.

To walk through what i have done i created the instance and changed the HTTP and HTTPs security settings to anywhere.

After that i launched the instance then running these commands

   ubuntu@ip-172-31-41-27:~ sudo apt-get update
   ubuntu@ip-172-31-41-27:~$ sudo apt-get install python-pip python-dev 
   nginx git
   ubuntu@ip-172-31-41-27:~$ sudo apt-get update
   ubuntu@ip-172-31-41-27:~$ sudo pip install virtualenv
   ubuntu@ip-172-31-41-27:~/portfolio$ virtualenv venv --python=python3
   ubuntu@ip-172-31-41-27:~/portfolio$ source venv/bin/activate
   (venv)ubuntu@ip-172-31-41-27:~/portfolio$ pip install -r               
   requirements.txt
   (venv) ubuntu@ip-172-31-41-27:~/portfolio$ pip install django bcrypt        
   django-extensions
   (venv) ubuntu@ip-172-31-41-27:~/portfolio$ pip install gunicorn

i edited the settings.py

 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = False

 ALLOWED_HOSTS = ['52.14.89.55']
 STATIC_ROOT = os.path.join(BASE_DIR, "static/")

then run,

  (venv) ubuntu@ip-172-31-41-27:~/portfolio$ python manage.py 
  collectstatic

followed by,

 ubuntu@ip-172-31-41-27:~/portfolio$ sudo vim 
  /etc/systemd/system/gunicorn.service

where I add

 [Unit]
 Description=gunicorn daemon
 After=network.target
 [Service]
 User=ubuntu
 Group=www-data
 WorkingDirectory=/home/ubuntu/portfolio
 ExecStart=/home/ubuntu/portfolio/venv/bin/gunicorn --workers 3 --bind      
 unix:/home/ubuntu/portfolio/portfolio.sock portfolio.wsgi:application
 [Install]
 WantedBy=multi-user.target

followed by a gunicorn reboot

  ubuntu@ip-172-31-41-27:~/portfolio$ sudo systemctl daemon-reload
  ubuntu@ip-172-31-41-27:~/portfolio$ sudo systemctl start gunicorn
  ubuntu@ip-172-31-41-27:~/portfolio$ sudo systemctl enable gunicorn

finally,

 ubuntu@54.162.31.253:~$ sudo vim /etc/nginx/sites- 
 available/portfolio

adding

 server {
   listen 80;
   server_name 52.14.89.55;
   location = /favicon.ico { access_log off; log_not_found off; }
   location /static/ {
       root /home/ubuntu/portfolio;
   }
   location / {
       include proxy_params;
       proxy_pass http://unix:/home/ubuntu/portfolio/portfolio.sock;
   }
 }

creating the link

  ubuntu@ip-172-31-41-27:/etc/nginx/sites-enabled$ sudo ln -s 
  /etc/nginx/sites-available/portfolio /etc/nginx/sites-enabled
  ubuntu@ip-172-31-41-27:/etc/nginx/sites-enabled$ sudo nginx -t
  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful
        deleting the default

then restarting

  ubuntu@ip-172-31-41-27:/etc/nginx/sites-enabled$ sudo service nginx 
  restart

EDIT**

I changed the following codes to match exactly what I have done.

Andy Nguyen
  • 451
  • 5
  • 17
  • 1
    What do the nginx logs say? – Benjamin Hicks May 30 '18 at 17:46
  • hmm I am having trouble trying to check that. Would it be: error_log /var/log/nginx/nginx_error.log warn; – Andy Nguyen May 30 '18 at 18:03
  • Right. If you look at `/var/log/nginx/nginx_error.log` the last few lines of input might have something to say re: what's wrong in your configuration. – Benjamin Hicks May 30 '18 at 18:14
  • Im getting "does not exist" when I try to look there – Andy Nguyen May 30 '18 at 18:29
  • Do you see anything `nginx` related in `/var/log`? Either way, the location of the file should in all likelihood be somewhere in your `nginx.conf` – Benjamin Hicks May 30 '18 at 18:31
  • okay i found it, but nothing appears ubuntu@ip-172-31-41-27:/var/log/nginx$ sudo tail error.log ubuntu@ip-172-31-41-27:/var/log/nginx$ – Andy Nguyen May 30 '18 at 18:36
  • That's strange, as it should be noting the error 500s even if nothing from gunicorn is bubbling up. (I do notice the ip has changed). – Benjamin Hicks May 30 '18 at 18:43
  • Ahh right, the IP from up above is from the instructions/notes i have set for myself. Here i am just running it again. I was getting Gateway error 500 yesterday but now its just saying Internal Server error. Restarted the whole deployment process twice now and I can't seem to figure out what I am doing wrong. – Andy Nguyen May 30 '18 at 18:46
  • It's very likely a blooper if you haven't replaced `{{your.EC2.ip}}` with an actual IP address or gotten it from your environment somehow. – Benjamin Hicks May 30 '18 at 18:53

0 Answers0