• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to configure Nginx Virtual Host in Debian 11.3

  • 00:40 lsb_release -a
  • 00:56 systemctl status nginx
  • 01:10 cd /var/www/html/
  • 01:20 mkdir site1 site2
  • 01:34 cd site1
  • 01:45 vim index.html
  • 02:20 cd site2
  • 02:26 vim index.html
  • 02:52 cp /etc/nginx/sites-available/default /etc/nginx/sites-available/site1.conf
  • 03:25 cp /etc/nginx/sites-available/default /etc/nginx/sites-available/site2.conf
  • 03:57 vim /etc/nginx/sites-available/site1.conf
  • 04:58 vim /etc/nginx/sites-available/site2.conf
  • 06:10 rm /etc/nginx/sites-enabled/default
  • 06:32 ln -s /etc/nginx/sites-available/site1.conf /etc/nginx/sites-enabled/
  • 06:57 ln -s /etc/nginx/sites-available/site2.conf /etc/nginx/sites-enabled/
  • 07:28 sudo nginx -t
  • 07:44 systemctl restart nginx
  • 07:58 vim /etc/hosts
{{postValue.id}}

To Configure Nginx Virtual Host On Debian 11.3

Introduction:

Virtual Hosting is a method that facilitates hosting multiple domains on a web server. Virtual Hosting is of two types Name based and IP based. While multiple sites can be run on the same IP address with Name-based Virtual Hosting, IP-based virtual hosting can have various IP addresses for each site. This article simplifies the configuration procedure of a name-based Nginx Virtual Host in Debian.

Installation Procedure:

Step 1: Check the OS version by using the below command

[root@linuxhelp: ~#] lsb_release –a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11	
Codename:	bullseye

Step 2: Check the status from Nginx service by using the below command

[root@linuxhelp: ~#] systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-10-31 00:22:41 IST; 36s ago
       Docs: man:nginx(8)
   Main PID: 4254 (nginx)
      Tasks: 2 (limit: 3450)
     Memory: 3.0M
        CPU: 17ms
     CGroup: /system.slice/nginx.service
             ├─4254 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─4257 nginx: worker process
Oct 31 00:22:41 linuxhelp systemd[1]: Starting A high performance web server and a reverse proxy server...

Step 3: Next go to the html directory and create two directories by using the following commands.

[root@linuxhelp: ~#] cd /var/www/html/
[root@linuxhelp: ~#] mkdir site1 site2

Step 4: Once the directories are created, use the below command to create a file with text in the site1 directory.

[root@linuxhelp:/var/www/html: ~#] cd site1
[root@linuxhelp:/var/www/html/site1: ~#] vim index.html

snap 1

Step 5: Repeat the same for site2 directory by using the below command.

[root@linuxhelp:/var/www/html: ~#] cd site 2
[root@linuxhelp:/var/www/html/site2: ~#] vim index.html

snap 2

Step 6: Now, use the below commands to create server block files.

[root@linuxhelp: ~#] cp /etc/nginx/sites-available/default /etc/nginx/sites-available/site1.conf
[root@linuxhelp: ~#] cp /etc/nginx/sites-available/default /etc/nginx/sites-available/site2.conf

Step 7: Next Configure the site1.conf file by using the below command.

[root@linuxhelp: ~#] vim /etc/nginx/sites-available/site1.conf

snap 3

Step 8: Now configure the site2.conf file by using the below command, Make sure you remove default server behind listen 80 and listen [::]80.

[root@linuxhelp: ~#] vim /etc/nginx/sites-available/site2.conf

snap 4

Step 9: Now remove the default server block by using the below command.

[root@linuxhelp: ~#] rm /etc/nginx/sites-enabled/default

Step 10: Now enable the new server block by running the below command.

[root@linuxhelp: ~#] ln -s /etc/nginx/sites-available/site1.conf /etc/nginx/sites-enabled/
[root@linuxhelp: ~#] ln -s /etc/nginx/sites-available/site2.conf /etc/nginx/sites-enabled/

Step 11: Now check the Nginx configuration with the help of below command.

[root@linuxhelp: ~#] sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Step 12: After checking the Nginx configuration, restart the Nginx service by running the below command.

[root@linuxhelp: ~#] systemctl restart nginx

Step 13: Now edit your hosts file by entering your IP address and domain name using below command.

[root@linuxhelp: ~#] vim /etc/hosts
192.168.6.137   www.linuxhelp1.com
192.168.6.137   www.linuxhelp2.com

Step 14: Next go to the browser, browse the first virtual domain and type www.linuxhelp1.com as shown in the below image. snap 5

Step 15: Next go to the browser, browse the first virtual domain and type www.linuxhelp2.com as shown in the below image snap 6

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to configure Nginx virtual host in Debian 11.3. Your feedback is much welcome.

Tags:
connor
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is the role of Nginx?

A

Nginx is a high-performance, highly scalable, highly available web server, reverse proxy server, and web accelerator (combining the features of an HTTP load balancer, content cache, and more).

Q

How does the Nginx virtual host work?

A

Nginx does not have Virtual hosts, it has “Server Blocks” that use the server name and listen to directives to bind to TCP sockets.

Q

Where is Nginx virtual host?

A

All configuration files for Nginx virtual hosts are stored in the /etc/nginx/sites-available/ folder. The best way is to create a separate file for each website on the server.

Q

Can Nginx have multiple servers?

A

Alternatively, you can also add the 2 server blocks to NGINX's default configuration file at /etc/nginx/nginx. conf if you want to configure multiple host names in NGINX.

Q

What is the Nginx default server?

A

The default server is the first one listed in the nginx. conf file, unless you include the default_server parameter to the listen directive to explicitly designate a server as the default.

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 Luk Van De Looverbosch ?
How to create a root ?

Hello,
How to create root@linuxhelp in Linux Mint 20.1 64-bit ?
Thanks in advance for your reply.
Best regards.

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.