Kundinformation

Molnservrar Hjälp

Configure NGINX Server Blocks - Ubuntu or Debian 7

Difficulty: 2Time: 30 minutes

If you want to host websites on your server running NGINX (which you probably do), you can use NGINX server blocks. Server blocks are the NGINX equivalent of Apache's virtual hosts - they let you direct incoming HTTP traffic for a domain name to a particular directory on your server.

Server blocks are most often recommended when you want to host multiple websites on the same server, but we recommend creating server blocks for all of your websites including the first.

Throughout this article, we'll use an example domain - coolexample.com - but you should replace it with the domain name or subdomain you want to host on your server.

Install NGINX

To get NGINX on your server, you should install it as part of a LEMP stack. How you do that depends on your OS:

Note: If you get an error when restarting NGINX, it is likely that you have not properly changed the server block files in the sites-available directory. Make sure that you have all your { } brackets closed and that all directives end in a semicolon.

Point your domain name to your server

If your domain name isn't currently loading another website, you should point it to your server to test your new config.

How you do this depends on where your domain name is registered and whose server you're using:

Changes to your domain can take up to 48 hours to display across the internet. However, once they do, you can visit your domain name and view the test page you created earlier!

Adding more server blocks

Because we had the foresight to create a template for our configuration, you can easily add more server blocks by just completing the steps in the Create a server block for your site and Point your domain name to your server sections.

Next step

Now that you have NGINX up and running, you can do things like install WordPress or Drupal on your sites.