VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

โ‡ฑ How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS | DigitalOcean


How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS

Published on April 26, 2014
Not using Ubuntu 14.04?
Choose a different version or distribution.
Ubuntu 14.04
๐Ÿ‘ How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS

Introduction

When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server.

In this guide, weโ€™ll discuss how to configure server blocks in Nginx on an Ubuntu 14.04 server.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

Tutorial Series: Introduction to Nginx and LEMP on Ubuntu 14.04

This tutorial series helps sysadmins set up a new web server using the LEMP stack, focusing on Nginx setup with virtual blocks. This will let you serve multiple websites from one Droplet.

Youโ€™ll start by setting up your Ubuntu 14.04 server and end with multiple virtual blocks set up for your websites. An Nginx configuration guide is included at the end for reference.

About the author

Former Senior Technical Writer at DigitalOcean, specializing in DevOps topics across multiple Linux distributions, including Ubuntu 18.04, 20.04, 22.04, as well as Debian 10 and 11.

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Great tutorial, very thorough - thanks!

Good article - just one nit-picky thing:

sudo service nginx restart is perfectly valid, but if you have a busy site, you might drop a couple of connections.

Safer, cleaner (and easier!) is to follow this tip Iโ€™ve been using since I found it on stackoverflow, which comes in very useful if youโ€™re making lots of changes or experimenting and tweaking:

alias n='/etc/init.d/nginx configtest && sudo /etc/init.d/nginx reload'

from then on, just hit n and enter. Instance new config, tested and reloaded if itโ€™s valid.

If you like the alias, just

sudo nano ~/.bash_aliases

add that alias line following the correct format and then

source ~/.bash_aliases

so you wonโ€™t need to reload the shell.

(I wonโ€™t delve into the whole /var/www vs /usr/share/nginx/html debate because Iโ€™m still not decided which is correct! )

Awesome, thanks!!

Hey, this worked perfectly with my first two test domains, but for some reason once I moved my actual domain in itโ€™s pointing to one of the test domains rather than to its own folder even though I followed the exact same steps. Any idea why?

Thanks!

@jcalifa: Could you post your Nginx configurations on a pastebin? That would make it much easier to help you.

@gugaalves: Add a new virtualhost with the following config:

server {
 listen 80;
 server_name www.domain.com;

 return 301 http://domain.com$request_uri;
}

and restart nginx.

I found that the line

server_names_hash_bucket_size: 64;

Caused and โ€˜unknown directiveโ€™ error when starting nginx and has to remove the colon for it to work:

server_names_hash_bucket_size 64;

Also, this line did not exist to be un-commented as descrived above, so you add it inside the http area:

http {
 server_names_hash_bucket_size 64;

...

}
๐Ÿ‘ Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOceanโ€™s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow โ€” whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

ยฉ 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.