How to Configure Nginx VirtualHost in OpenSUSE

To Configure Nginx VirtualHost in OpenSUSE

Virtual Hosting is a technique for hosting multiple domains on a single web server. There are two types of Virtual Hosting - Name based and IP based. The former enables hosting multiple sites on the same IP address, and the latter can let a user to have different IP address for each site.



For the Nginx installation


To Configure Nginx VirtualHost

The initial step is to get into the web root directory and create two directories under the document root directory.

linuxhelp:~ # cd /srv/www/htdocs/
linuxhelp:/srv/www/htdocs # mkdir sites1 sites2

Once the directories are created, open the sites1 directory. Create a file with text in it. Repeat the same for the sites2 directory. Use the following command for doing it.

linuxhelp:/srv/www/htdocs/site1 # vim index.html

Now create a separate directory on nginx configuration with the following command.

 linuxhelp:~ # mkdir  /etc/nginx/sites

After that, use the following command to create two new virtual host configuration files under sites directory.

linuxhelp:/etc/nginx/sites # touch test1.conf test2.conf

Now open the  newly created test1.conf file and configure it as follows. Repeat the same procedure for the other file.

linuxhelp:/etc/nginx/sites # vim test1.conf
listen 80;
location /{
root /var/www/htdocs/sites1;
index index.html;

After configuring the above two files, use the following command to open the Nginx configuration file and edit it accordingly.

linuxhelp:/etc/nginx # vim nginx.conf
http {
include mime.types;
include /etc/nginx/sites/*.conf;
default_type application/octet-stream;

Now issue the following command to check the configuration status of Nginx

linuxhelp:/etc/nginx # nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Once the configuration status is checked, edit the host file.

linuxhelp:~ # vim /etc/hosts

Once it is done, invoke the following command for restarting Nginx service.

linuxhelp:~ # systemctl restart nginx.service



After Nginx is restarted, open the browser and navigate to the first virtual domain by typing The browser displays the content of that particular file as follows.


Now to check the second virtual domain, type and see its content.

You can deploy the same method to create multiple domains.


Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Nginx OpenSUSE Web Server Virtualhost
user image Author :  Noah