Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

yourdomain.com. Name the file yourdomain.com and place it in sites-
enabled or sites-available, as described above. This file includes
comments that will help you fill in your specific details:


Click here to view code image
#this first server module is just a rewrite directive – it is not
required, and you
#can make the rewrite go the other way, to force NOT using www
server {
listen 80; #sets the HTTP port from which the
website is served
server_name www.yourdomain.com; #names the server using the www
prefix


        #if a   server  request is  made    without www,    this    next    line    will
rewrite it
rewrite ^/(.*) http://yourdomain.com/$1 permanent;
}

#this   second  server  module  tells   Nginx   where   to  find    the files   when
requested
server {
listen 80; #sets the HTTP port from which the
website is served
server_name yourdomain.com; #names the server being
configured
location / { #sets the location of the files
being served
root /home/<yourusername>/public_html/yourdomain.com/; #top
directory for the site
index index.html;
}
}

Earlier in this section, we mentioned that you may place the files for your
website wherever you like. The root line in the file just created is where you
place this information. Here we use ’s personal home
folder and place within it a directory called public_html specifically
created for holding website files. Because our example anticipates serving
multiple websites with this one server, it goes further and creates a directory
for the sample website, yourdomain.com.


At this point, everything should work for simple HTML sites. To add
additional domains, repeat these steps for each domain being served.


Setting Up PHP

Free download pdf