Next we're going to update the allowed host setting in our Django configuration
to fix this bad request error that you can see behind me open up the atom
editor and load up the settings dot py file in our project then scroll up to
the top of the file and find the allowed host setting here allowed hosts is a
setting that allows us to enable access via specific domain names it's a
security feature to make sure that if somebody just finds a random IP address
for our server they can't access the application unless they use a valid host
name so we need to specify the host names that we want to allow to connect
to our server in the allowed host option
the host name that we need to add is
the host name for our server which is in the ec2 configuration here and is the
public dns option
so copy the contents of that and then open up the atom editor
and we're going to paste it as a string into this list here we also need to add
the local host so that it still works on our vagrant server so in a second item
in this list type 127.0.0.1
I'm going to break this out into separate lines to
keep it within the character limit and then make sure you save the file now
that we've made a change to the project we can demonstrate how to update changes
on our server after we push them to github
let's start by committing and pushing this change to github so open up the
terminal and make sure you have a window open that is on a local machine and not
connected to our server
select our project directory then type git add dot
to add any additional files and then type git commit - am and we'll add the doc
string added allowed hosts
then type git push origin to push the changes up to
github
now that the changes are on github we
can run our update script on the server to
pull the latest changes so go back to the server that is connected via SSH if
it's disconnected then just run the SSH command again to connect back to the
server and we're going to navigate to the location on the server where our
project files are stored so type CD forward slash usr forward slash local forward slash apps
forward slash profiles rest api and hit enter
if you type LS you should see all of the
project files here and what we're going to do is we're going to run sudo sh dot
forward slash deploy forward slash update
this is the command that will run
the update script that will update the application based on the latest
github changes hit enter on that and it should pull the latest changes down and
then run all of the commands necessary to restart the server
okay you can see
that the script has finished running so let's go to our browser and let's open
up the tab that we got the bad requests on and hit refresh now you
can see it says not found because there's no root mapped to the base of
the URL so we're going to just add forward slash API forward slash and you
should see the root of our API
you should also see if you put forward slash
admin the admin page
the only thing left to do now is to create a super user on
our server so that we can log into it using our user account
so open up the
terminal and make sure that you are in the forward slash USR slash local slash
apps slash profiles REST API and then we're going to run the following command
to add a super user
we're going to run sudo env slash bin slash Python and then
we're going to run manage dot py create super user and hit enter
then enter an email address I'm going to put mark@londonappdev.com hit enter and
then a name I'm going to put mark and then for the password I'm just going to put
password one two three but make sure you put a secure password when you create
this because your site will be publicly accessible which will open it up to be
attacked
so once you've entered the password hit enter I'm going to re enter
the password hit enter I'm going to put yes and now you can see the super user has been
created so let's test this I'm going to go over to the Django admin type mark@londonappdev.com
password password 1 2 3 hit enter and you can see
that I've logged into the Django admin and now our app is working as expected
so that's how you deploy the app to AWS on an ec2 instance