Apache Virtual Hosts

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone I'm Jacob calf and I'm the nerd of the street and today we are taking a look at Apache virtual hosts [Music] okay guys so in a lot of my tutorials I like to use the Apache web server I've been using it for a really long time and I'm really comfortable using it there are other web servers out there but Apache is the software of my choice when I'm hosting a website now virtual hosts in Apache are a topic that I have talked about in previous videos in a lot of videos actually basically any time I'm showing how to set up a web application I'm usually doing that in the context of an Apache virtual host so if you've been watching my videos for a while you might already have a basic understanding of what virtual hosts are and how they work however a user on the nirn of the street forums last week was spreading misinformation about Apache virtual hosts and seems to have a lack of understanding of what they are so I figured I'd make a video just talking about Apache virtual hosts what they do and how to set them up so when you start web server software on a server that web server is going to bind itself to one or more network ports on the server usually for a web server that's going to be ports 80 and 443 so port 80 is used for HTTP traffic and port 443 is used for encrypted HTTP traffic which is using TLS now when a computer goes to visit a website it's going to send a packet over the Internet to the server and the server is going to receive that packet and the first thing the server is going to do the operating system of the server the network stack is going to look at the port that the packet was sent to the destination port and it's going to use that destination port to determine what application to forward that information along to now what that means since a web browser is going to be searching for websites using ports 80 and 443 what that means is that your web server can only have one application that is receiving the requests for ports 80 and 443 now let's say I want to host two different web sites on the same web server the server needs to be able to tell when a packet comes in requesting for the web site it needs to be able to tell what website is being requested so that it knows what information to send back now since the port will use HTTPS as an example since the port is going to be 443 for every single packet no matter what website you're going to the server can't use the port number alone the destination port to determine which website a client is trying to access all that the server is going to do the networking stack and the operating system is going to say this is port 443 I'm sending this packet to Apache and from there Apache has to decide what it's going to send back now the Apache web server has a concept called virtual hosts and virtual hosts can actually be used for two different things they can be used to serve different websites based on the IP address that's being requested or they can be used to serve different web sites based on the domain name that's being used now the IP address version of virtual hosts it came first and basically that is for if your server actually has multiple public IP addresses if it has multiple network cards or if it's otherwise configured to where it is talking on several different IP addresses and if each different website is going to be requested through a different IP address it's a very unusual setup but if that was your setup you could still use virtual hosts to accomplish that you could say if a client requests port 80 on 1.2.3.4 send website a if a client requests port 80 on five six seven eight send website B that's the IP address type of virtual hosts and then there's named virtual hosts as well now named virtual hosts is what we normally use because most servers only have a single public IP address usually they only need a single public IP address so when you type in the name of a website like example.com the client is going to first perform DNS lookup to find an IP address that matches example.com then it's going to send a packet to that IP address and to the destination port of either 80 or 443 now when the server receives that Apache can actually look and once the server gives Apache the packet once it says okay this is port 443 I'm sending this packet to Apache what Apache can do is it can look inside of the HTTP headers so that is a higher level Pia of information it's no longer part of the basic structure of the packet this is now headers within the HTTP application data Apache is going to look at what server name was requested and from there it can make a decision what directory do I serve files out of based on the server name so you can't have say Apache and nginx another web server both listening for virtual hosts on the same port that's not possible because before the packet gets to either one of those web servers the operating system needs to look at the port and it uses the port number to still figure out which server software to send that packet to first so if you want to run Apache and nginx on the same web server one of them has to see every single packet on that port first and then it is possible to set up a reverse proxy so that Apache if it receives a certain server name it's going to turn around and then send an internal request to Engine X on a different port engine X response to Apache and then Apache responds to the client that's possible to do and I've done it on some of my servers now that's outside the scope of the video for today but I wanted to give you first just a high-level explanation of how virtual hosts work so with that in mind we're gonna cut to the desktop and I'm gonna show you just a simple configuration for setting up multiple virtual hosts on your Apache web server all right guys here we are on the desktop now for this video today I have spun up a digitalocean droplet as you can see the droplet has a public IP address here and then over in my Linode control panel where I have my DNS settings saved I've added 3a records all pointing to the same IP address so I've got my app nerd on the street comm pointing to 138 . 68-54 dot 129 I've got other app nerd in the street comm also pointing to the same IP address and then third app comm is also pointing to the same IP address now those DNS records have already propagated so what that means is if I open up a terminal here and I ping my app turn on the street comm um it's going to ping the 138 address I can also paying other app turn of the street comm and then I can also paying third app turn of the street comm so all three of these domain names are pointing to the exact same IP address and this is why we need a patch named virtual hosts because when a web browser goes to contact these three IP addresses from a network standpoint it's gonna look exactly the same because it's talking to the same IP address but the HTTP header that's got the hostname in it will be different and that's what apache uses to differentiate between the different sites so I'm going to go ahead and SSH into this IP address this is a Debian 10 server I'm going to quickly just update all the software on the server alright and everything is up-to-date now so if I just go in my web browser and I never get to the IP address itself let's see what that looks like first first you can see it says this IP address refused to connect that's because the server is not currently listening on port 80 or port 443 because Apache has not been installed yet so to fix that we can just install Apache and if you're on Sint OS or Red Hat based distributions the package name will probably be HTTP D because Apache is the name of an organization HTTP D is technically the name of the webserver itself but the webserver is the most popular thing that Apache makes so a lot of people just refer to HTTP D as Apache and that's what debian-based distros do but that is installed now and if we do a systemctl stannis Apache - you can see that it is active and running so if we go back to our web browser and we refresh you can see now we have a default page now we can see that our domain name is working as well if we go to HTTP colon slash slash my app dot nerd on the street comm we'll see the exact same Apache default page I can open up new tabs and I can go to other app known in the street comm you can see it's the exact same page and then if we go to third app turn of the street comm once again this this server only has one website stored on it right now and so all three of these pages look exactly the same so our goal is I want people going to different websites to actually see different websites but I want to use the same server to host all three websites so we're gonna do that with Apache virtual hosts now here on our server we can take a look at our Apache configuration that's going to be stored in slash etc' slash Apache - and if I do a listing on this directory you can see our main Apache configuration file is Apache - Kampf now in most of my videos I'm working inside of these two directories bottom sites available in sites enabled I'm gonna talk about those in a moment but it's best if we understand where although the configuration is actually coming from and the Apache to.com file is the main Apache configuration file this is actually the singular file that is sourced when Apache starts up so we can enter into the Apache T comp file and just take a look around you can see there's a lot of comments at the top that actually explain how this works of course you're watching a video so you're gonna get that anyway now the Apache - comp file is where we can set global settings for the Apache web server first and foremost so the location of our process ID file keepalive settings for connections the user in group that our Apache server is running as and locations for our global logging now at the bottom of the file if we scroll all the way to the bottom here you can see these two lines include optional and the first one is including our comp enabled directory and the second line is including our sites enabled directory so the sites enable directory isn't actually special in itself the reason why the sites enable directory is red is because it's specified here in the Apache comp rectory if you wanted to you could change this sites enable directory in this configuration file to point to any other directory on your system that contains Apache configuration files sites enabled is just the default and I'd recommend you keep it that way because it's easiest to understand when we're using the default setup so this line right here is saying include in our configuration after everything else that's already been specified include everything in the site's enabled directory that ends with kampf so if there's a file in this directory that ends with dot back or dot test or dot anything else it's not going to be applied only any file name that ends with kampf is going to be included in the configuration when we start the Apache web server so with that in mind let's take a look at sites enabled so I can do an LS dash L on sites enabled and you can see what we've got here is 0 0 0 - default Kampf now this is actually a link we can tell that in two different ways for one thing the leftmost character in the permissions here is L for link and then for another thing we've got literally an arrow pointing to the file that is linking to so the site's enabled slash zero zero zero default comp file that is a link that's pointing to sites available zero zero zero default Kampf so that's another great thing to understand on a conceptual level is that the files inside of sites enabled they're just files we could place a text file inside of sites enabled if we wanted to most of the time it's more common to link from sites enabled to sites available because then we can use a two in site and a two-disc site to turn sites on and off automatically but you don't have to use those tools you could do this manually if you wanted to you could add and remove links if you wanted to or you could actually just put your text files directly inside of the sites enabled directory if you wanted to so we know that sites available zero zero zero default Kampf is being included in our Apache configuration because the Apache to.com file includes sites enabled and sites enabled points to sites available for this file so let's take a look inside of this zero zero zero default comp file at the top of the file you can see we already have our first virtual host specified and this virtual host it's got an asterisk in the 'no colon and eighty now this wildcard here this is referring to any IP address this wildcard has nothing to do with the server name the server name is specified later but the wild-card up here in the virtual host block that is saying any IP address it doesn't matter if you connect on the public IP address if we've got an ipv6 address that we can also refer to the server by if we've got clients on our local network connecting via a private IP address it doesn't matter what IP address what network card this request comes in through any IP address if there's a packet on port 80 we're gonna send it to this virtual host now taking a look farther down here in the file there is a server name directive you can see it is commented out by default and that's because the Apache web server is going to have a default virtual host which is what we're looking at right now and any server name that's not explicitly specified later is going to be sent to the default virtual host so this is why all three of our domain names up here have the same page none of these domain names are specified in our Apache configuration right now so Apache is going to just send website from the default virtual host back now the document route option here that's where we specify the actual location of the files so this Apache to Debian default page we know is stored in var WW HTML I'll copy that so we can confirm that in just a moment and then each virtual host can log its errors and access separately by default they're all going to log into the same log files and that's why we've got the combined keyword of the entir now I'm running a lot of virtual hosts on my main web server right now and so I do have them broken out so that each individual virtual host or at least the clusters of them that are related are logging to their own separate error files and access files and if we take a look further down here the only other thing we're doing is we're closing this virtual host section so this virtual host block is being included in our configuration once again because this file is linked to insights - enabled insights - enabled is referenced in the Apache - comm file now if we wanted to we could actually put a virtual host block we could type in this same syntax in the main Apache - comp file and we can specify all of our virtual hosts there you don't even need to have them separated out into different configuration files if you don't want to that's just the way they set it up by default because it's easier to keep track of your virtual hosts when each one has a separate configuration file I'm gonna exit out of that file if we do an LS dash L on that directory that's referenced inside of this 0 0 0 default kampf you can see there is an index.html file and if we cat out var WW HTML index.html you can see here Apache 2 Debian default page so this is the physical file that we're seeing when we're going to this website right now so let's get started then I want to start by having my app Narula Street Calm go to a different virtual host in order to do that the first thing I'm going to do is I'm going to make a directory where that website's files are going to be stored I'm gonna do that in var WW once again it can be anywhere on your server I like to keep things together so that they're easier to keep track of so I'm gonna make a directory called my app and if we list out our directory now you can see we've got var www HTML and var www my app so now I can CD into my app and I can go ahead and make a new index.htm file I'll just make a really simple HTML file here alright so I've just written a really simple HTML file it's just got a single header in it and a single paragraph so I'm gonna save that file and I want to serve this my app directory whenever somebody requests my app turn of the street calm so we'll go back to our Etsy apache2 and I'm going to make a new file under sites available and I'm gonna make it called my app Kampf so this is a blank text file and I'm gonna start typing out I've got my virtual host block of configuration and I'm going to use the wild card here : 80 and that's because I don't care what IP address somebody is accessing the server from I only care about if they're accessing it with the my app name if I wanted to tie this down so that this is only accessible via my public 138 IP address I could type in 138 dot 68 54.1 29 but I don't really care about that I just want anybody accessing my app Burnham Street com to get sent to this app so I'm gonna go ahead and close the virtual host block just so I don't forget to later and then the first option we're going to add inside of here is the server name directive and we're gonna make it my app dot nerd on the street comm so this is where we're telling Apache okay take a look at the HTTP header of the packet and if the HTTP header is requesting my app turn of the street com then we're gonna use this virtual host block not the other virtual host block now just so you know Apache is going to look due to the structure of this configuration it's going to look at the IP address first then it's going to look at the server name after it matches the IP address so Apache is going to use the most specifically matching virtual host block and we'll take a look at that later so that we understand the full implications of that but after it narrows down to the set of virtual hosts that are most closely matching the IP address and port then it's going to look for an exact match of the server name in all of the virtual hosts if it finds one it's going to use that virtual host if it does not find any matches of the server name in any of the virtual hosts that are most specifically matching the IP address and port then it's just going to use the first virtual host that's listed in that zero zero zero default comp file the reason it's called zero zero zero default is so that it's always first in alphabetical sorting of that directory anything in the site's enabled directory will be included in the configuration file a wild card is going to glob and it's going to list in alphabetical order so the zero zero zero default com since it starts with three zeros it's always going to be unless you're intentionally changing something it's pretty much always going to be first alphabetically and that's why it's called the default configuration file if you renamed that zero zero zero default comp file to Z Z Z default kampf now it's going to be last and it's no longer going to be the default virtual host whatever's first alphabetically is going to be the default virtual host within the site's enabled directory now if you specify a virtual host in the main apache2 kampf file before that include line then it's going to take precedence because it's being read in by Apache before any of the sites in Abel directory is being read so I hope that makes sense we've got our server name here now if you want to you can also include a server alias and so this is like if you've got my app dot in under the street comm but I also want wwm I appeared on the street comm because some people think that websites have to start with www this is very common to do and from here you can use other configuration to redirect from WW back to the main my app turn on the street comm now I don't actually have this set up in my DNS so wwm I ignore the Street comm it's not going to resolve to this IP address so that would never reach the server anyway so I'm gonna comet that line out but I wanted to mention that that is an option and it's a very commonly used option now there is a server admin directive and that's part of the default virtual host file so we'll include it in ours as well I'm going to put Jacob at nerd in the street comm since I am the administrator of the server now the server admin directive is kind of deprecated it's not actually used anywhere in Apache itself anymore it is possible to use a PHP call to print out the server admin an error message or something like that if you wanted to set that up for your own application but the next and most important thing that we need is the document root directive and this is going to tell Apache what directory to serve when somebody goes to the server name so the document root is going to be VAR w w my app once again this does not have to match the name of your configuration file if you wanted it to be different you can make it different now in this virtual host file you can also include things like a directory block of configuration that would look something like this and if you want to put in allow override all or some sort of configuration like that that would let users put an HT access file inside of this directory and override the global configuration for Apache you can do that within your virtual host file and it's going to take precedence over the global configuration since it's more specific in the virtual host file we don't have any need for that right now so I'll delete that part we do want to tell Apache where the error log is going to go so we're going to use the Apache log directory which is var log Apache 2 in Debian by default and then I'm going to make this one called error my app dot log and then I'll do custom log Apache log directory slash access my app dot log combined now I think I mentioned offhand earlier that the combined word is because all of the different sites use the same log file by default but that's not actually true as you can see this directive here is not called access log it is called custom log and this log is very customizable within the main Apache configuration file you can tell Apache what kind of events you do or don't want to log and what you want the format to look like so combined is the default formatting of the file it's going to include all the information you need generally to read the file and differentiate between different lines and different virtual hosts within the file but we're going to separate our file out by specifying a different location for it and that's everything we really need for this virtual host so I'm going to go ahead and save it now that virtual host file the my app comp file that's not part of our Apache configuration yet because the Apache 2 comp file does not specify sites available as the configuration directory it only includes the sites enabled directory which if we take a look and of sites enabled we do not have my app in there right now so the reason why I like to use these two directories and most Apache users do is because they make it really easy for us they include a command a to incite my app Kampf and that is going to enable site my app so you can see the changes have not taken place yet until we reload the configuration which we'll do in a second but if we do another LS in our sites enable directory now you can see there is a link my app Kampf which is pointing to sites available dot my app Kampf once again if you wanted to manually create a link with LNS sites available my app sites enabled my app Kampf this command would create a symbolic link from sites enabled my app kampf back to sites available slash my app kampf and these don't even need to be named the same thing i could call it my app XYZ Kampf it's still going to be included in sites enabled and it's still going to point to the file that contains the configuration so this would work and we could do it but Apache gives us this little bit of abstraction with allowing us to turn sites on and off to enable and disable sites by managing the links for us so I'm gonna go ahead and just let Apache do its job in that regard so we'll go ahead and activate the new configuration and now if we come back to our web browser if we refresh my app turn on the street comm now we get my app now if we come back over to other app turn of the street comm and we refresh that we still get the default page and the same thing for third app because we don't have any virtual hosts that are specifying either of these domains as their server name so they're falling back to the default which is the first listed which is incidentally going to be the first alphabetically in sites enabled which is 0 0 0 default now in order to get other app working all we have to do is the exact same thing I'm actually just gonna copy our sites available slash my app Kampf I'm going to copy it to sites available other app Kampf I'm going to create a directory real quick at var WW other app and I'm going to nano into sites available slash other app Kampf and I'm gonna change a few things first of all viously will change the server name to say other app nerd in the street comm and by the way wildcards are a thing that you can use in server names as well if you want anything known of the street comm to point to one directory or anything dot example.com to point to a different directory you can do that but we're gonna put other app turn of the street comm in this virtual host I'm actually going to specify the IP address here once again just to kind of demonstrate what this is going to do so 138 dot 68-54 dot 129 this is the public IP address of our server so this will work if I specify it manually because our client when it connects this is the only IP address on this server so I know the client is going to be connecting on this IP address I also know that because that's the IP that the domains DNS record is pointing to and then I'll change the document route to borrow WW other app and I'm going to change the error log to other app dot log and the custom log the access log to access other app dot log all right and we will reload apache one more time now I can go ahead and I can refresh other app turn of the street com it's still pointing to the Debian default page and that's because we didn't enable the site so I can a to insight other app to make a link to that from sites enabled to sites available and now we reload apache now we can reload and you can see we've just got a blank directory if I do an LS dash L on 4ww other app you can see the directory does exist but it is empty there's not an index.html file in here nor is there anything else so since there's no index we're just going to get an actual directory listing you can turn this off if you want to for security reasons but by default we've got the directory listing and there is nothing in the listing because that directory is empty now our my app turn of the street comm is also pointing to the index of and it's just got the same directory now and it's no longer displaying its file and if we come back over to third app dot nerd in the street comm it's also pointing to this empty directory what happens well first of all I am just gonna do a quick touch test file for rww other app test file just so that we can verify that this is not some other directory that's being displayed all three of these virtual hosts all three of these domains actually are now pointing to the same virtual host you can see we're accessing them through different domains but we are seeing the same directory the reason why that's occurring is once again because like I said Apache is first going to match the most specific IP address match for your virtual host before it looks at the server name at all so just to show you what Apache is looking at in aggregate we know there are no virtual host files within the main Apache to kampf file so I'm just gonna cat out my sites enabled file and with a wild star glob so that we see exactly what Apache is seeing so here's what Apache is doing it loaded in the configuration we've got our default virtual host which comes first it does come first still alphabetically then we've got our second virtual host as my app third one is other app so why are all three of these virtual hosts pointing to var WW other app well that's because the virtual host for other app includes the IP address in the name Apache looked through and it said okay I've got a packet that was destined for this IP address the packet is always going to be destined for an IP address that's just how networking works it's going to need an IP address a clients not going to be able to send a server a request without using its IP address so Apache said I've got a packet it's going to this IP address and it says which of these three virtual hosts is the most specific IP address match well these two are just wild cards the first virtual host is a wild card the second one's a wild card third ones actually got an exact match so that's the most specific IP address match so Apache says okay this is the most specific IP address match and so it's going to be what we use for all three of those requests now what I can do is I can come in and I can go to sites available slash my app and I can also specify the IP address in this configuration file 138 68-54 129 and I can also nano into and it doesn't matter if you edit sites available or sites enabled because if you if you type in a command like this to edit our sites enabled slash 0 0 0 default it's a simple Inc you're still editing the one insights available physically on the server so we're just gonna specify the IP address in all three of these and we're gonna reload apache and now we can come back and refresh and you can see my app is now pointing to my app again and third app is now pointing to the default again because now since we specified the IP address and all three of those files apache says okay we've got a match here a match here in a match here those are our three most specific matches they're all equally specific in terms of their matches for the IP address option and then from there it says okay well I've got multiple IP address matches now I need to look at the server name to find out which one matches there so my app obviously that's an exact match up here and then third app has not been added to our configuration yet so it's going to use the first one listed which is incidentally the zero-zero-zero default comp file all right so the last thing I want to do is add one more virtual host for the third app and so for that I'm gonna make directory var WW third app and I'm gonna nano into var www third app dot HTM and I'm gonna make one more time an HTML file here alright so I've got an HTML file that is going to be our third app HTML file so once again just to demonstrate how the configuration format works I am going to nano into this time I'm going to add a virtual host inside of Apache to calm itself I'm not going to use the included files now once again this is bad form I wouldn't normally recommend doing this I'm doing this to show you for educational purposes how this works I'm gonna come down to our include lines not those include lines I'm gonna come down to the here we go include optional so if we have anything inside of sites and able to include that now above the science enabled directory I'm going to add virtual host I still need since I specified the IP address and the other three files I'm gonna need the IP address in this one otherwise it's not going to be the most specific match so I'm gonna put that in : 80 and if you're using HTTPS by the way let's encrypt is going to set up when you run cert bot to set let's encrypt up cert bot will create usually or it will at least offer to create another virtual host file for you for Apache but if you're doing it manually for an HTTP website that's using port 443 you just changed the port right there from 80 to 443 and you will need to do that for every virtual host you'll need to make a copy and change the port or you can just change the port and not have a port 80 version but if you do that in a client tries to reach out to port 80 if somebody doesn't type in the HTTP and their web browser defaults to HTTP then they wouldn't get a response so it's usually best to keep one of each when you're running HTTP have a port 80 virtual host that's redirecting to the port floor for three virtual hosts using a rewrite rule which I might do a separate video on in the future rewrite rules but for now we've got our virtual host and I'm gonna put in server name third app da turn of the street comm server admin Jacob at 9 in the street comm don't email me by the way if you have questions about computers go to nerd of the street comm I've been getting a lot of emails recently but then we're gonna put it in our document root VAR ww3 app directory we'll put in our error log and once again here we could type in vard log Apache - error log but it's better for them to use the configuration variable since it exists anyway by default alright so we've got that virtual host specified I'm gonna go ahead and save this file and I'm gonna reload Apache to looks like it failed to load let's see what the problem is systemctl status apache - invalid command custom log alright so i misspelled custom log here if you make typos in your configuration file that will not work alright so custom log will reload apache - there we go so that configuration has been applied now and if we come back and we refresh third app note of the street comm hmm it's getting index of oh it looks like I accidentally put my third app dot HTM file inside of far WWE earlier I need to move that from VAR w w3 f HTM to VAR w w third app / their depth at each TM making a lot of mistakes right now but now that we've moved that file we can refresh and you can see third app dot HTM is right there I should probably also rename that from third app to index dot HTM so that it actually displays by default and now we can refresh and hey there's our third app now that was a couple of things going wrong but I wasn't planning here's one thing that I was planning though if we come back over to other app and we refresh oh they're all still working right because each virtual host that's specified right now has a server name in it or rather all three of these domains are specified in a virtual host so I'm going to go ahead and choose my app to pick on here I'm going to go ahead and disable with a two-disc site my app I'm gonna disable that site I'm also going to remove dot slash sites available slash my app so that my app configuration is no longer there I didn't need to be the second step there but I did it anyway now I am gonna come into my sites available zero zero zero default comp file and I'm gonna change the document root for the default to my app let's say this is my main website so if somebody manages to reach my server on a domain name that I wasn't expecting I do want to show them my main web site so we're gonna save that now I'm gonna do system CTL reload Apache two however even though I've just changed the default to point to the same directory of my app when I reload this it's actually gonna load third app now the reason for this once again is because Apache is first gonna look at all of the IP addresses it's gonna find the closest match if there's more than one closest match then it's going to look at the server names and it's going to look for an exact match of server name now the server name it's not going to say well how close is this server name or that server name to what we're looking for if there's not an exact match for the server name the it is just going to use the first virtual host that is listed and so even though if we do an LS dash L on our sites enabled we can see that 0 0 0 default Kampf is still the first alphabetically listed file in that directory if we nano back into our Apache 2 comp file and we go to the bottom you can see we placed our virtual host 4/3 app we placed it above the include line for the sites enabled so this virtual host is being read in before anything inside of sites enabled I can fix this by commenting out this line down here and I can move this include optional line back up above the other virtual host file I'm gonna put sites enabled slash everything Kampf and we can reload a systemctl reload Apache 2 so now once again sites enabled will be loaded first default is the first file and site of sites enabled so our default is going to be my app since that is what the default file is pointing to so this video has gotten wait longer than I planned it for such a simple topic I do just want to show you a quick command that can be useful it's Apache to CTL - capital s and this is gonna show you some stuff it's gonna show you if there are any configuration warnings you can see I don't have my server name directive set but down here you can see it's also gonna show us our virtual host configuration and it's going to show you some other potentially useful stuff like what user and group Apache is gonna be running as but the virtual host configuration is neat because it's gonna break down what you've got specified we've got our IP address here called an ad because all three of our files have that specified it says our default virtual host file it doesn't have a server name listed but it is our default file because that's the first one that's listed alphabetically it's going to list it again because even though it's the default it is also a specified virtual host so if we did list but we can actually go in there and you don't have to not have a server name listed in your default we can come into sites enabled 0 0 0 default comp and we can set our server name to my app actually I'm just going to call it a bunch of gibberish dot nerd of the street that's not actually a real domain name I'm gonna do systemctl reload apache2 and my app journalist recom will still work because it was using the default virtual host anyway and if we take a look at Apache CTL - s again you can see default server let me make my term illest a little bit bigger yeah default server is bunch of gibberish turn on the street comm so my app is going to use the default however if I were to make a DNS record with this bunch of gibberish then it would also explicitly use the default configuration file and then we've got other app and third app also listed in that order and third app is last in this case not because it's last alphabetically it's last because it's specified in Apache - Kampf online 226 which is lower than the include line for these other three and I'm not gonna set up HTTP right now I think this videos gotten long enough but I will just show you this is what the Apache CTL output looks like on my main web server right now you can see I'm getting my money's worth out of that single web server I'm hosting all these different websites on some of them are personal some of them are for other people but you can see that I've got my : 4 4 3 virtual hosts with all of its server name directives inside of it and then I've got the : 80 virtual host with all of its name v hosts inside of it so yeah guys like I said I wanted to make this video because I talk about Apache virtual hosts a lot I know that some people don't understand them a lot of my tutorials people just try and copy and paste things and they try and deviate in small ways and then it get confused when things break because they don't actually understand what they're doing so I wanted to make a video just about Apache virtual hosts that way in the future if anybody doesn't understand it patchy virtual hosts instead of having to type things out and explain it to them I can just send them a link to this video so I hope this was helpful for you I hope you learned something I certainly learned a couple of things about how some of the preference and hierarchy works for this configuration while I was researching for this video if this video was helpful to you consider joining the nerd Club at nerd club Natsuko it's a big help that helps me spend more time making videos like this but for now that's everything I have to talk about in this video so i'm jacob puffin in the street and I'll see you guys in the next one bye [Music]
Info
Channel: Nerd on the Street
Views: 34,154
Rating: undefined out of 5
Keywords: nerdonthestreet, jacob, kauffmann, jacobgkau, Apache, Apache HTTP Server, httpd, web server, virtual hosts, multiple sites, multiple websites, virtual sites, vhosts, namevhost, different websites, multiple domains, ServerName, ServerAlias, directory, how to, configuration, default, setup, set up, install, same server, ports, IP addresses, VirtualHost
Id: x5fWSWdM4F8
Channel Id: undefined
Length: 40min 19sec (2419 seconds)
Published: Sat May 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.