• 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

This Article Has Been Shared 234 Times!

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

  • Cloud Computing IaaS : Infrastructure as a Service

    Cloud Computing IaaS or Infrastructure as a Service is the lowest level in cloud computing.IT infrastructure like archive and backup services are actually IaaS.

  • Cloud Computing Free Trial of 30 days from Fujitsu Global Cloud

    Cloud Computing Free Trials becoming standard now. After Microsoft Azure, Fujitsu is offering enterprise-class Global Cloud Platform for FREE trial.

  • The Right Cloud Service : Determining the Right Cloud Provider

    The Right Cloud Service should be selected for you work or business like selecting the right partner. Here is the best process for determining Right Cloud Provider.

  • Hybrid Cloud Environment : Is it a Good Approach to Adapt ?

    Hybrid Cloud environments might appear as something logically consistent, but the technical points should necessarily be taken into account while adaptation.

  • Cloud That Lights Up : Beautiful Cloud Sculpture Made up of Burnt Out Bulbs

    Cloud That Lights Up. Neither anything about Cloud Computing nor Coding.It is a sculpture made up of burnt out bulbs and illuminated using CFC with pull switch.

Additionally, 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

  • What Online Casinos Have No Deposit Bonus in Australia March 30, 2023
  • Four Foolproof Tips To Never Run Out Of Blog Ideas For Your Website March 28, 2023
  • The Interactive Entertainment Serving as a Tech Proving Ground March 28, 2023
  • Is it Good to Run Apache Web server and MySQL Database on Separate Cloud Servers? March 27, 2023
  • Advantages of Cloud Server Over Dedicated Server for Hosting WordPress March 26, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Set Up IP-based Virtual Hosts in Nginx Ubuntu Cloud Server," in The Customize Windows, January 5, 2015, March 30, 2023, https://thecustomizewindows.com/2015/01/set-ip-based-virtual-hosts-nginx-ubuntu-cloud-server/.

Source:The Customize Windows, JiMA.in

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT