First, we need to select the Ubuntu as the image on our server.
After installing Ubuntu, we need to configure DNS on out domain. In case our domain is www.domain.com, we need to point it's DNS settings to Digitalocean's server. At our domain registrar, we point our domain to:
ssh username@yoursite.com -p definedport
After we are asked for the password, we will access our remote server.
When connected to the remote server, first thing we need to do is aces superuser privilege and instal nginx. We do it with the following command:
sudo apt-get install nginx
After this step, nginx will be installed but not running. In order to start the nginx service, we type into the terminal
sudo service nginx start
Our nginx is now up and running. Now we need to create a virtual host and a folder which will contain our file. We do it wit the command
sudo mkdir -p /var/www/domain.com/public_html
We need to change the permissions, so that everyone can read our files, but only root use can modify them. We do it with chmod command:
sudo chmod 755 /var/www
Nginx by default looks for the index.html file which we need to create, and put some content in it:
sudo nano /var/www/domain.com/public_html/index.html
Now we need to create our virtual host file in nginx's site-available folder
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/domain.com
sudo nano /etc/nginx/sites-available/domain.com
Now we have our configuration opened in a tex editor, with some default values. Our new server requires the following configuration:
server {
listen 80; ## this is default HTTP port
root /var/www/domain.com/public_html;
index index.html index.htm index.php; ##this is the list of files nginx will search for
# Make site accessible from http://localhost/
server_name domain.com;
}
Now we save it and exit. We need to draw a parallel from available to enabled sites, so we do it with
sudo ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled/domain.com
In the final step, we need to restart our nginx server to apply changes. We do it with
sudo service nginx restart
.
At this point, our site should be up and running.
From what is seen here, configuring nginx is even easier in the beginning than configuring Apache.
For sites with a lot of workload and if we pay attention to our resources, it is a much better choice than Apache.