# Python Flask Tutorial: How to Use a Custom Domain Name for Our Application

## Метаданные

- **Канал:** Corey Schafer
- **YouTube:** https://www.youtube.com/watch?v=LUFn-QVcmB8
- **Дата:** 17.01.2019
- **Длительность:** 23:59
- **Просмотры:** 114,875
- **Источник:** https://ekstraktznaniy.ru/video/12027

## Описание

In this Python Flask Tutorial, we will be learning how to set up a custom domain name for our application. We will use NameCheap as our domain registrar and Linode to host our server. Let's get started...

If you would like $20 of free credit towards a Linode account, then you can use my link here to sign up: 
https://linode.com/coreyschafer

Buy a domain at NameCheap:
https://namecheap.pxf.io/c/1358746/408749/5618

Linode DNS Documentation:
https://linode.com/docs/platform/manager/dns-manager-new-manager/


✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms

✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join

✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY

✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey's Public Amazon Wishlist
http://a.co/inIyro1

✅ Equipment I

## Транскрипт

### Segment 1 (00:00 - 05:00) []

hey there how's it going everybody in this video we're going to learn how to add a custom domain name to our website that we deployed in the last video so we deployed our application to a private Linux server that anyone could access from a browser but we're still accessing this site using an IP address in this video we'll be walking through the complete process of buying a domain name and setting this up so that when we navigate to that domain name it takes us to our application so let's go ahead and get started so first we need to register a domain name now registering a domain name does cost money but it is fairly cheap they usually run about $10 to12 a year so that usually comes out to about a dollar a month now in order to register a domain name you're going to have to do that through something called a domain registar now there are a lot of these out there you can use whichever one you prefer uh the registar that I'm going to use in this video is called name cheep and that is at namecheap. com now nameche isn't a sponsor of this video or anything like that uh just used them for some time now and I've found them easy to use but there are also registar through Google which is at domains. goole. com uh most of you have probably heard of GoDaddy which is another one that you can use uh so you can use any of those but I'm going to be using name cheep in this video and if you'd like to use name cheep as well then I'll put an affiliate Link in the description section below where you can go and create an account if you would like to use them but once you've created an account with your registar then we can search for domain names by going to their website and usually they have a search bar where you can search for domains so this one here is right front and center now if you've never bought a domain name before then it's actually pretty difficult to find one that isn't taken uh so if you want a domain with four or five letters then you're pretty much going to be out of luck because those are likely all taken uh and even ones that you might not think would be taken might actually be so for example let's say that we wanted uh the domain for our application to be something like you know my awesom blog. com so if I said my awesom blog. com if I search for this then this is going to come back and say that this is taken now you also have the option to make an offer if that's a domain that you really want uh but there's no guarantee that the person who owns that domain will even get that offer uh so anytime I see a domain is taken I usually just move on to something else I don't even try to make an offer on it so it might take you some trial and error before you actually find one um so I search earlier and I think if I wanted my domain to be like my awesom app. com then I think that this is still available so if I search the registar for that then we can see that my awesom app. com is available and that it's available for 888 a year which is less than a dollar a month so that's pretty good now some registrars will also offer you other top level domains as well so we can see that they also uh searched my awesome app. net my awesome app. org doio and things like that so you can add those if you ever want uh to pick up those domain names as well but for this tutorial I'm just going to get my awesom app. com so I'm adding that to my cart now and once that's done I'll go to view cart and now in the cart we're going to see that it's going to offer us some other add-ons uh which is pretty common whenever you check out on sites like this uh I usually don't take the add-ons um so we're going to register for this domain you can choose you know one year two years I'm just going to do one year since this is probably just a throwaway domain um it says that there's also a fee Associated that is uh this I can fee that's going to be through any of those um now this who is guard we can see that it is enabled and set up to Auto renew and that is 0 that is free forever uh now I actually do recommend uh checking this because a who is guard uh what that does is it uh protects your privacy with buying this domain so a lot of people don't know this but whenever you register a domain uh you actually have to put in a lot of information like your name your address uh how to get a hold of you and things like that now if you don't use some type of protection in this case it's something called who is guard then that information is going to be available to people uh who look up that information so for example I have a who is guard on my personal website so if I pull up my terminal here there is a Linux command called who is and if I say who is and go to Corey ms. com that is my main webs website if I type that in then we can see if I scroll up here a little bit uh we can see that the registar for this is it blocks all my private information so the who is server is at who is. namecheap. com um if I go up here things like the address uh this is through uh a who is guard so it blocks all this stuff but if I didn't have this blocked then my name would show up here my address possibly my phone number and email address and I don't like that I like

### Segment 2 (05:00 - 10:00) [5:00]

having privacy uh and uh so if you use the who is guard then that is what that does so a little off tangent there but that's why I think that is important but none of this other stuff I ever really get so there's a premium DNS uh there's all kinds of sales here with like private email uh you know how to use Gmail with your domain stuff like that uh I do all that stuff myself uh so I am not going to need that I'm just going to use the domain so I'm going to go to confirm order here and now we're taken to the page where we can pay for that order uh so I've already got a credit card set up on here uh but if you haven't set that up then you're going to have to use like a credit card or PayPal or something like that uh in order to buy your domain so I'm going to go to pay now and actually pay for this okay so my payment was completed so now that domain name should be mine so now I'm going to go down here and click on manage beside this domain name so I'll click on manage and now this takes me to a list of domains that I have registered through name cheep so we can see that the only other one I have registered right now is my personal website cms. com but now we also have my awesom app. com let me see if I can make this a little larger so that it is easier to see okay so now we have our domain name and now we're ready to connect this uh to our application now in the last video the service that I used to uh set up my application was Len no so I have lenoe up here in the browser now if you're not using Len node then this process is probably going to be very similar uh just not exactly the same but uh just you know look at the documentation for whatever service you're using and it's likely going to be very similar to this now Len node if we click here on domains then we can see that I have my cms. com domain name here uh now over here they have some documentation uh to this DNS manager and that's how to set up a new domain name now I already have this pulled up here in the browser and I'm also going to add a link to this in the description section below if you'd like to follow along but they have some very good documentation in here on how to set up our domain name so if we go down here to our DNS uh setup checklist then we can see that it walks through the process so register purchase a domain name if you haven't already so that's what we just now did using name cheep and now it says set your domain name to use Len noes name servers you'll need to do this on your domain registar website then wait up to 24 hours for the change to take effect so what they mean here if I click on this use Leno's name servers uh these are Leno's name servers here ns1 Len no. com ns2 Len no. com and we can see it says after you purchase your domain log into your domain register control panel and set the name uh servers for your domain name to the entries below so that's what we're going to do so we're going to go back to name cheep and we're going to set the equal to these Len no name servers here so I'm going to go to my domain list and you're going to see a option over here for manage I'm going to click on manage and now we can see that we have a lot of different options for managing our domain name so we can add years to our registration who is guard uh buy some other services now what I'm interested in is uh the name servers here so the name servers I want to do a custom DM DNS right now it's set up to this uh name Che basic DNS now what that means is if I go to The Domain that I just bought then it's probably redirecting me to uh something name Che oriented so if I go to my awesome app. com then we can see that it's that name sheep is actually handling this domain name right now it says uh this domain is registered at name sheep it was recently registered please check back later so what we're going to do is instead let Len no handle this traffic instead of name cheep so that's what we're going to do with those name servers so instead of this name cheep basic DNS I'm going to come down here to custom DNS and now we will add let's see that was five servers from Lode I'm going to go back to the documentation here and go down to the name servers and I'm just going to copy these in now instead of going back and forth uh I'm just going to add all five of these and change them manually so that was ns1 ns2 ns3 ns4 and ns5. Len no. com so I will save that okay and once that is updated we can see up here it says DNS name servers usually take 48 Hours uh to switch over so this could take some time uh I've actually never seen it take 48 Hours uh on Len no's documentation they say it can be uh 24 hours um so it's going to take a little bit of time but usually that's done pretty quickly so I'm going to pause this video until you know for a little while and I'll pick up uh after some

### Segment 3 (10:00 - 15:00) [10:00]

time uh so that change has probably taken effect and actually while you're waiting for that change to take effect there are some things that we can do on the node system uh to get this set up further so we can see here if we scroll back up to the checklist uh so we have now done number two here we've set our domain name to use the Len noes uh name servers so that's done so moving on to number three use the DNS manager to add a domain Zone and then start adding some basic DNS records uh so at that point uh we can go back to our domains here and what it means by adding a domain Zone if we click on our domains then I'm going to go to add a domain and on the domain here it's going to ask us what domain we want to add uh so I'm going to say my awesome app. com and the email address I'm just going to say admin aty awom app. com that's not actually set up yet uh but I'm just going to add that in for now and we can add some tags if we want to add some tags to this domain I'm going to leave that empty so I will click on create okay and after we click on create uh we're going to see that we are going to be able to add some DNS records here now this can look a little intimidating because there's all kinds of different records uh we're not going to look in depth at all of these but if you want then you can look each of these up individually so we have Ana record NS record MX record a AAA record um now if you want some more walkthrough on this then the uh documentation that I have pulled up here walks you through all of this so if I scroll down just a little bit then we can see that there's a DNS manager section and this is where it shows us how we can add a domain so we already added the domain like we did scroll down a little bit more we already did this part where we added our domain Zone and our uh email address if I scroll down a little more here then we get to the add record section so uh we've already seen the add records page and now it's showing us how we can add a single record so the page is divided up in different sections each type of a DNS record locate the section for the type of DNS record that you want to add then click add a DNS record uh so what we're going to add is a an a record here so I'm going to go back to our section here and I'm going to say add an a record and when we we're going to need a host name and an IP address now for the host name if I go back to the documentation here we can see that the host name is going to be something like www and the IP address is going to be the IP address of our application so if I go back to the a record here so for the host name I'm going to fill in www and the IP address uh is going to be the IP address of our application so to find this I'm just going to cancel this for now if we go back to our dashboard then we can see that I have my list of servers here uh so if you wanted the uh so I've got the D Jango server and the Flash server for the flash tutorials and the Django tutorials uh if we want the IP address of our flask server then we can click on that Len node and within the summary here we can see that the IP address is listed here right up uh in the front uh you can also get that from the networking tab where we have the SSH command so from either of those locations so I am going to copy that go back to our domains go back to my awesome app domain and down here in the a records let's add that so for the host name that's going to be www and for the IP address I'm going to paste in the IP address that we got from our flask server so now I'm going to save that okay so after we've saved that let's go back to the documentation here and let's scroll up to the top to get back to our checklist so now with the checklist here we've done these top three things here we've done the registration we've uh set up our name servers we used the DNS manager to add a domain name Zone and added our basic DNS records now it's saying we should set a reverse DNS now if we open this link here and look at the documentation for setting up this reverse DNS uh this documentation is actually a little bit older and I don't think they've had a chance to update this yet um because if we look at their uh examples here you can tell that this doesn't look like the cloud manager that we have in Lum node this is actually their old uh manager at manage. Len no. com so I'm not going to follow this uh documentation exactly uh we'll just kind of do this uh the way that it's done in the new Cloud manager uh but this is a good documentation for just at least figuring out what reverse DNS is uh we can see here that it says computers use DNS to determine the IP address associated with a domain name reverse DNS look up does the opposite by

### Segment 4 (15:00 - 20:00) [15:00]

resolving an IP address to a domain name so instead of going uh from a domain name to an IP address like DNS usually is a reverse DNS goes from an IP address to a domain name so uh let's go ahead and get this set up so I'm going uh back to my Len node here and I'm going to click on Len noes and now we want to click on our uh server that we want to set up reverse DNS for so I'm going to click on our flask server now within here we're going to go into networking and within networking I'm going to scroll down to our ipv4 uh IP addresses now here is our ipv4 IP address now over here on the far right I'm going to click on this settings tab here and then go to edit R DNS that is reverse DNS if I click on that we can see it says edit reverse DNS uh so we already have something in here but now we are going to put our domain name instead so I'm going to type this in www. my awesome app. com and you're going to put whatever your domain name is in there so I'm going to save that now at this point you might get this error message that says we were unable to perform a lookup for your domain at this time uh now the reason for this is because uh all of the changes that we've made to the name servers and the DNS records and all of that stuff all of that takes time to take effect uh so all this means is that those changes have not taken effect yet so it can take you know anywhere from you a couple of hours to maybe 24 hours it usually doesn't take that long I mean it can take you know just a few minutes uh but if you get this air then that is what that means so the only thing that you can do is pause the video and just wait for those changes to take effect uh I know that that's frustrating to pause in the middle of tutorials but it's really the only thing you can do is wait so I'm going to pause this video and whenever this is working I will come back to this and we can pick up from here okay so I paused the video and I went and took about a 30 minute break or so uh so now these DNS records and name servers should all be updated at this time like I said 15 to 30 minutes is usually uh about how long it takes anytime I've done this but in the worst case scenario it can take a few hours and like the websites say it can even take up to 24 hours but I've never had it take that long usually 15 to 30 minutes is good enough so now uh that we've taken a break let's try to save this and see if these DNS uh changes have taken effect so I'll go up here and click on Save okay and that works so that must have been enough time for those changes to take effect uh so we can see that now we have a reverse DNS set up for my awesome app app. com for this IP address so now let's actually try to open this up in the browser uh using our domain name so I'm going to copy our domain name here and I'm going to open up a new tab and I'm going to uh paste this in and go there and we can see that now when we navigate to www. my awom app. com it opens up our flask application so that's exactly what we wanted uh so that's good we're no longer using our IP address um so now let's test out some of the functionality just to make sure that this is working properly um so if I log in then I can uh sign in with my email um I think that was uh the password I used yep so there we go um so let me try to do a couple of things here let me uh create a post and it looks like new posts are working um if I update a post and we can see that uh our routes are also working with our domain name so this is going to uh my awesom app. com slost sl28 update uh so that is working as well it's not filling in the IP address for those things um okay so the updated post worked uh if I delete a post then that works as well let's see if I can uh update a profile picture so I'll select a different profile picture here and that seems to be working as well um we can log out and we could even go in and uh go to our forgot password and send a forgot password to our uh email address so if I do that then we can see uh an email has been sent with instructions to reset your password uh and I actually just saw that email pop up on my phone so that seems to be working as well um so that is all of the functionality okay so this seems to be working well uh now one thing I want to try here is if we remove the www

### Segment 5 (20:00 - 23:00) [20:00]

and just go to my awesome app. com uh I actually uh don't know if this will work okay so that doesn't work now if we want to set that up to work as well then we could go back into our lodde and go to domains and we could go to our my awesome app. com domain and within these records we could simply create another record so I'll add another a record and within here we are just going to leave the host name blank uh instead of putting that www and the IP address uh we will put the same one in so I can see the IP address over here uh for my application it is 45. 5 6. 75 one5 okay so if I save that uh then that adds that record in now again that record isn't going to update uh immediately it could take you know 5 10 15 20 minutes something like that in the worst case scenario a couple of hours to update um but eventually that should start working and uh you can go to either my awesome app. com or www. my awom app. com but I'm not going to wait for that to update right now I'm just going to go back to uh the www version of the website okay so hopefully you got your domain name working with your application and would feel comfortable doing this for your applications in the future uh in this video we set this up using Len no and name cheep but no matter what services you use uh it should be a very similar process to what we did here now speaking of Leno lenoe was kind enough to sponsor this video so I'm going to go back to my dashboard here real quick so like I was saying uh Lode was kind enough to sponsor this video and I've used them for many years and have recommended them to people long before I even had any sponsors so if you get a chance I would highly recommend giving them a shot uh like we saw in earlier videos they have this new and improved Cloud manager that makes spinning up servers fast and easy and you can choose from available images when you spin those servers up or you can even upload your own custom image and if you're doing something that is fairly common then they have thing these things called stack scripts that allow you to spin up a server with all of the relevant software ready to go uh so for example if you're making something like a WordPress site or something like that then you can simply choose their WordPress stack script that spends up a server with WordPress ready to go uh also they have nine worldwide data centers so far and they have two more set to open this year in 2019 so no matter where you are you should be able to spin up a server that is close to your audience so if you want to check them out then feel free to use my referral Link in the description section below and you can get $20 of credit applied to your account to try them out okay so with that said I think that is going to do it for this video now there is still a lot more that we can do with this site uh so for example if we look here in the address bar of our browser at the top left uh we can see that this website is not secure uh which means that it is using HTTP instead of https now most websites these days should have https set up uh but that is a topic for another video uh for now we have our live application with our custom domain name working uh so that is great so if anyone does have any questions about what we covered in this video then feel free to ask in the comments section below and I'll do my best to answer those and if you enjoy these tutorials and would like to support them then there are several ways you can do that the easiest way is to Simply like the video and give it a thumbs up and also it's a huge help to share these videos with anyone who you think would find them useful and if you have the means you can contribute through patreon and there's a link to that page in the description section below be sure to subscribe for future videos and thank you all for watching
