• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to Install and Configure Nginx Virtual-Host in Debian

941

To Install Nginx and Configure Virtual-Host in Debian

Virtual hosting is a technique used to run more than one website on a single server. It allows the users to use multiple host names while sharing its resources. This article explains the installation and configuration process of Nginx Virtual-Host in Debian.

Installation of Nginx Virtual-Host

First install Nginx with the ' apt-get install' command.

root@linuxhelp:~# apt-get install nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:    
  nginx-common nginx-full
Suggested packages:
  fcgiwrap nginx-doc
The following NEW packages will be installed:
  nginx nginx-common nginx-full
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 591 kB of archives.
After this operation, 1,413 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://security.debian.org/ jessie/updates/main nginx-common all 1.6.2-5+deb8u4 [88.1 kB]
Get:2 http://security.debian.org/ jessie/updates/main nginx-full amd64 1.6.2-5+deb8u4 [430 kB]
Get:3 http://security.debian.org/ jessie/updates/main nginx all 1.6.2-5+deb8u4 [72.6 kB]
Fetched 591 kB in 2s (209 kB/s) 
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 136779 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.6.2-5+deb8u4_all.deb ...
Unpacking nginx-common (1.6.2-5+deb8u4) ...
Selecting previously unselected package nginx-full.
Preparing to unpack .../nginx-full_1.6.2-5+deb8u4_amd64.deb ...
Unpacking nginx-full (1.6.2-5+deb8u4) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.6.2-5+deb8u4_all.deb ...
Unpacking nginx (1.6.2-5+deb8u4) ...
Processing triggers for systemd (215-17+deb8u5) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up nginx-common (1.6.2-5+deb8u4) ...
Setting up nginx-full (1.6.2-5+deb8u4) ...
Setting up nginx (1.6.2-5+deb8u4) ...
Processing triggers for systemd (215-17+deb8u5) ...


Utilize the following command to start the Nginx service.

root@linuxhelp:~# service nginx start

Now its time to check the output. Open the web browser with the respective IP address.

browser

To Configure Virtual-Host

Create the directory for virtual-host.

root@linuxhelp:~# mkdir -p /var/www/vhost1.com
root@linuxhelp:~# mkdir -p /var/www/vhost2.com

Then create the html file for the virtual host domains.

root@linuxhelp:~# nano /var/www/vhost1.com/ index.html

VHOST 1
 This is first virtualhost page...! 

root@linuxhelp:~# nano /var/www/vhost2.com/ index.html

VHOST 2
 This is second virtualhost page...! 

Open the nginx.conf file and check the ' include /etc/nginx/conf.d/*.conf' line is enable or not. If its not enable, just enable it.

root@linuxhelp:~# nano /etc/nginx/nginx.conf


Then create the ' vhost.conf' file into ' /etc/nginx/conf.d/' directory for virtual host configuration.

root@linuxhelp:~# nano /etc/nginx/conf.d/vhost.conf
#first vhost configuration

server {
listen 80 
server_name     test.vhost1.com 
location / {
root    /var/www/vhost1.com 
index   index.html index.htm 
}
}

#second vhost configuration

server {
listen 80 
server_name     test.vhost2.com 
location / {
root    /var/www/vhost2.com 
index   index.html index.htm 
}
}

Next add the virtual host domain name with IP into the ' hosts' file

root@linuxhelp:~# nano /etc/hosts
192.168.5.130   test.vhost1.com
192.168.5.130   test.vhost2.com

Restart the Nginx service to take effect.

root@linuxhelp:~# service nginx restart

Once the above process is completed successfully, open the browser with the created domain names to check the output.

domain

second_virtualhost

Tags:
landon
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

How can I customize/add a configuration for a VHOST in nginx?

A

You can modify the default template by
# vim /usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php
and then,
# /usr/local/psa/admin/sbin/httpdmng --reconfigure-all

Q

Does NGINX Plus support session persistence?

A

NGINX Plus support for cookie-insert, variable-based routing and learn session persistence. Please see: Application Load Balancing with NGINX Plus

Q

What is the proper location for the virtual hosts config file that won't get overwritten?

A

Simply stop using WebStation Virtual hosts (remove them to avoid duplicates) and set up your own in:
CODE: SELECT ALL

/etc/nginx/sites-enabled

Q

When should I use NGINX open source?

A

You can use Nginx As Opensource,
you want to compile in 3rd party modules not included in NGINX Plus Extras, or you want to create your own custom modules;
you want to maintain your own packages and security fixes;
you are working in an environment where you don’t require support.

Q

How do I obtain NGINX Plus from the repository?

A

To obtain NGINX Plus, please follow the instructions at https://cs.nginx.com/repo_setup

Related Tutorials in How to Install and Configure Nginx Virtual-Host in Debian

Related Tutorials in How to Install and Configure Nginx Virtual-Host in Debian

How to Configure Nginx as a Reverse Proxy in CentOS
How to Configure Nginx as a Reverse Proxy in CentOS
Nov 26, 2016
How to install Multiple Nginx instances in same Server on CentOS 6
How to install Multiple Nginx instances in same Server on CentOS 6
Oct 26, 2017
How to configure Nginx Load Balancer in CentOS
How to configure Nginx Load Balancer in CentOS
Nov 9, 2016
How to configure Apache Virtual Host in OpenSUSE
How to configure Apache Virtual Host in OpenSUSE
Nov 1, 2016
How to configure Apache virtual host in FreeBSD
How to configure Apache virtual host in FreeBSD
Oct 31, 2016
How to install Nagios with Nginx on CentOS
How to install Nagios with Nginx on CentOS
Aug 1, 2017
How to create virtual host in NGINX (Both Name and IP based)
How to create virtual host in NGINX (Both Name and IP based)
Jul 18, 2016
How to install Nginx from Source Code on CentOS 7
How to install Nginx from Source Code on CentOS 7
Nov 7, 2017

Related Forums in How to Install and Configure Nginx Virtual-Host in Debian

Related Forums in How to Install and Configure Nginx Virtual-Host in Debian

Ubuntu
matthew class=
Failed to enable unit: Refusing to operate on linked unit file sshd.service
Apr 15, 2019
Nginx
gokulravichandran2 class=
Failed to start A high performance web server and a reverse proxy server
Dec 23, 2018
CentOS
AadrikaAnshu class=
What does fastcgi_params file contain and what is it used for in nginx on CentOS 7.6
Jun 14, 2019
Nginx
AadrikaAnshu class=
A common misconfiguration is that the 'session.save_path' directive is not pointing to a valid directory.
Jun 15, 2019
Nginx
levi class=
php files are downloading not executing in nginx
Apr 21, 2017
Virtualhost
issacjoseph class=
"Oops! Your system prevents changing hosts file. Laragon will temporarily disable "Auto crate virtual hosts" feature!" in laragon
Nov 27, 2020
Nginx
lucky class=
[emerg] 32915#32915: bind() to 0.0.0.0:8989 failed (13: Permission denied)
Jun 13, 2019
Nginx
rokkotnik class=
CentOS Nginx load balancer two different apps
Mar 15, 2020
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Gibbson ?
How do i run both nginx and apache in same instance on centos

Hi...,

my server is based centos operating system and my webserver is already running on Apache.... i need to run both apache and nginx on same instance ... please help me to implement this concept...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.