• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Set Up IP-based Virtual Hosts in Nginx Ubuntu Cloud Server

By Abhishek Ghosh January 5, 2015 11:27 am Updated on January 5, 2015

Set Up IP-based Virtual Hosts in Nginx Ubuntu Cloud Server

Advertisement

Here are simple steps to set up IP-based Virtual Hosts in Nginx running Ubuntu. IP-based Virtual Hosts will help to use two IP addresses on one server. Notice the title carefully – Set Up IP-based Virtual Hosts in Nginx Ubuntu Cloud Server. This is not exactly what we might do on a dedicated server. Dedicated costs a huge – in thousands of USD per month. Run a Blue Pill-Red Pill test to detect if you are running within a Virtualized OS Instance and fooled as Dedicated. However, if routers, hub, switch etc. are not different, it is not possible to detect; whether the server is really dedicated. Settings on a Dedicated demands more knowledge on UNIX and manpower in real life.

We talked about Virtual Hosts before in the linked article. Virtual Hosts can be – Name-Based, IP-Based, Port-Based etceteras. What you normally read in this and that websites are Name-Based Virtual Hosts.

 

Set Up IP-based Virtual Hosts in Nginx Ubuntu Cloud Server : Basics

 

We talked about Virtual Hosts before in the linked article. Virtual Hosts can be – Name-Based, IP-Based, Port-Based etceteras. What you normally read in this and that websites are Name-Based Virtual Hosts. At the time of writing this article, we have two IP address 15.125.77.166 and 15.125.77.27. Our setup is complex, this website has 5K posts right now, plus there is podcast and other stuffs. On a multi-tenant environment, we have lot of servers behind one domain. These are called – nodes. It is needed to distribute the load in a short sentence.

Advertisement

---

IP-based Virtual Hosts is exactly the opposite – one server but multiple websites. Now, these websites will also have multiple IPs. This is great for smaller websites, like my personal website dr.abhishekghosh.net and abhishekghosh.pro. One 01 GB server is enough to host them. But the hosting provider must have the facility to add allocate floating IPs. There will be an extra charge for this extra IP.

With different IP, it is easier to install SSL certificate, Google bots can not understand whether there is one server or multiple servers, cost reduction etc.

 

Set Up IP-based Virtual Hosts in Nginx Ubuntu Cloud Server : Steps

 

We are taking that, you can install Nginx normally and can run WordPress on Ubuntu. This amount of knowledge is mandatory. Normally install means – one server hosted on one website with one IP.

Suppose your Nginx has the public folder on :

Vim
1
/usr/share/nginx/html

If two domains are abhishekghosh.pro and abhishekghosh.net, then do lik these steps first :

Vim
1
2
3
4
5
6
7
cd /usr/share/nginx/html && ls
rm -r * && ls
mkdir abhishekghosh.pro abhishekghosh.net
chown -R www-data:www-data /usr/share/nginx/html/abhishekghosh.pro
chown -R www-data:www-data /usr/share/nginx/html/abhishekghosh.net
sudo chmod 755 /usr/share/nginx/html
nano /usr/share/nginx/html/abhishekghosh.pro/index.html

For both the domain’s index.html files, I need to put a bit different two plain html files :

Vim
1
2
3
4
5
6
7
8
<html>
  <head>
    <title>abhishekghosh.pro</title>
  </head>
  <body>
    <h1>Moron: abhishekghosh.pro is a Virtual Host</h1>
  </body>
</html>

and, second one :

Vim
1
nano /usr/share/nginx/html/abhishekghosh.net/index.html

Vim
1
2
3
4
5
6
7
8
<html>
  <head>
    <title>abhishekghosh.net</title>
  </head>
  <body>
    <h1>Imbecile: abhishekghosh.net is a Virtual Host</h1>
  </body>
</html>

Moron and Imbecile will help me to really understand whether the Virtual Hosts are properly set.

Read, but do not do these steps until we are telling you to do.
This is called Nginx Server blocks :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
nano /etc/nginx/conf.d/default.conf
# edit rightly
server {
server_name abhishekghosh.pro;
#create server log later and uncomment
#access_log logs/abhishekghosh-pro.access.log main;
root /usr/share/nginx/html/abhishekghosh.pro;
}
server {
server_name abhishekghosh.net;
#create server log later and uncomment
#access_log logs/abhishekghosh-net.access.log main;
root /usr/share/nginx/html/abhishekghosh.net;
}

Now reload Nginx :

Vim
1
nginx -t && service nginx reload

Up to this part, things are exactly like Name-based Virtual Hosts in Nginx. Yes, we could also edit this :

Vim
1
/etc/nginx/sites-available/default

and create two different settings, symlink to make essentially Name-based Virtual Hosts working in Nginx. To make it more easy to understand, if you edit this file :

Vim
1
nano /etc/nginx/nginx.conf

and play with these :

Vim
1
2
3
4
5
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
## or
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;

Rinse, Lather, Repeat.

You will understand the things are not rocket science, it is various peoples who wrote guides in their own used ways without informing that, other methods exist. This is kind of experts’ bias – doctors also do not offer too much alternative treatment options. Instead of editing /etc/nginx/conf.d/default.conf, we will edit /etc/nginx/sites-available/default and resume your doing from this steps. We asked you to stop, now start to do again.

Real part starts with running the command :

Vim
1
ifconfig

Install WordPress on Nginx With HHVM on Ubuntu Cloud Server

When one IP is set, you will see the output like this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
eth0      Link encap:Ethernet  HWaddr 04:01:31:a2:fe:01
          inet addr:104.131.164.225  Bcast:104.131.175.255  Mask:255.255.240.0
          inet6 addr: fe80::601:31ff:fea2:fe01/64 Scope:Link
          inet6 addr: 2604:a880:800:10::325:a001/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4033561 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4451922 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:807570148 (807.5 MB)  TX bytes:1343093157 (1.3 GB)
 
eth1      Link encap:Ethernet  HWaddr 04:01:31:a2:fe:02
          inet addr:10.132.177.245  Bcast:10.132.255.255  Mask:255.255.0.0
          inet6 addr: fe80::601:31ff:fea2:fe02/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:648 (648.0 B)  TX bytes:578 (578.0 B)
 
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:5748 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5748 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:567045 (567.0 KB)  TX bytes:567045 (567.0 KB)

If you edit this file :

Vim
1
nano /etc/hosts

and entries like :

Vim
1
2
3
127.0.0.1    localhost
10.0.0.2        abhishekghosh.pro
10.0.0.3        abhishekghosh.net

and restart :

Vim
1
/etc/init.d/dns-clean start

Linux will understand what we want to do – matter of subnet mask like HP Cloud.

Secondly, if we edit /etc/nginx/sites-available/default, we can make it listening to Public IP addresses. Copy the default file first :

Vim
1
2
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/abhishekghosh.net
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/abhishekghosh.pro

Delete all these :

Vim
1
2
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default

Symlink has been removed. We need to again symlink :

Vim
1
2
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default

Then edit each of the files :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
server
{
        listen 10.0.0.3:80;
        root /usr/share/nginx/html/abhishekghosh.net;
        index index.php index.html index.htm;
        server_name abhishekghosh.net;
        #access_log path/to/access.log;
        #error_log /path/to/error.log;
 
# Redirect server error pages
        location /
{
try_files $uri $uri/ /index.php;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html
{
        root /usr/share/nginx/html/abhishekghosh.net;
        }
# PHP scripts to FastCGI
location ~ \.php$
{
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
        }
}  

You need to edit both the files, then symlink each :

Vim
1
2
3
4
sudo ln -s /etc/nginx/sites-available/abhishekghosh.net /etc/nginx/sites-enabled/abhishekghosh.net
# symlink both or all domains after editing them, then
nginx -t
service nginx restart

I provided examples with 10.0.0.2, 10.0.0.3; depending on the Cloud Computing software, you have to replace it with Public IP either in both files or in one file () only. Yes, it is not difficult but very painful. After doing twice or thrice, if you are new, you’ll get used. Errors are due to improper permission, conflicting settings etc. cPanel like things are for that reason – hosting hundreds of domains with one IP plus enabling to assign one domain with a different IP in a scripted manner.

Always remember, best way to check header is curl -> curl -I abhishekghosh.net. Browser can fool some few seconds. There are gross things like – pointing the domain using a DNS server towards proper IP.

Now, there are complicated factors like firewall (for the main nodes of webhost), suppose if OpenStack not supported IP-based Virtual Hosts, then nothing could be done! Ask your web host first, because it is not very easy from networking point of view. Steps get used and become easy.

Tagged With set ip based virtual hosts ngnix cloud server , nginx ipbased virtual server
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Set Up IP-based Virtual Hosts in Nginx Ubuntu Cloud Server

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • How to Install WordPress : Ubuntu 16.04, Nginx, PHP7-FPM

    Here is Step by Step Guide on How to Install WordPress on Ubuntu 16.04, Nginx, PHP7-FPM, memcached & Percona MySQL 5.7 on Cloud Server or VPS.

  • Free SSL : How to Install Let’s Encrypt on Ubuntu, Nginx

    Here is Step by Step Commands to Use Free SSL by Let’s Encrypt. We will use aptitude software to install the certificate, it is very easy.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy