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

How to Configure Nginx Virtualhost in FreeBSD

973

To Configure Nginx Virtualhost in FreeBSD

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 configuration process of Nginx Virtual Host in FreeBSD.

Configuration of Nginx Virtualhost

First install the FEMP by using the following command.

https://www.linuxhelp.com/how-to-install-femp-in-freebsd/

Utilize the following command to check whether the Nginx is installed or not.

root@linuxhelp:~ # service -e
.
.
.
/usr/local/etc/rc.d/php-fpm
/usr/local/etc/rc.d/nginx
/usr/local/etc/rc.d/mysql-server
.
.
.
Done!

Create a new directory for virtualhost domains.

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


Then create the index.html file for both virtualhost domains.

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

FIRST VHOST
This is first virtualhost....!

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

SECOND VHOST
This is Second virtualhost....!

Now you need to configure the virtual host in nginx.conf file.

Configure virtualhost within the “ http” tag.

root@linuxhelp:~ # nano /usr/local/etc/nginx/nginx.conf
.
.
.
http { 
.
.
.
#first virtualhost
server {
        listen       80 
       server_name  test.vhost1.com 
        location / {
        root /var/www/vhost1.com 
        index  index.html index.htm 
        }
           }
#second virtualhost
server {
        listen       80 
       server_name  test.vhost2.com 
        location / {
        root /var/www/vhost2.com 
        index  index.html index.htm 
        }
           }

}


Immediately add the virtualhost domain in 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
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 655.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configu
ration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.


Now its time to access your virtual host domains in web browser. Open your web browser with the IP address.

Web_browser

Check your configured virtualhost as shown below,

configured virtualhost

Second_virtualhost

Tags:
connor
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

How to give user and group permission for all the files in Nginx?

A

For Nginx web servers the user and group name can be assigned as
# chown -R nginx:nginx

Q

We can define custom locations for the domain logs on the Nginx Web server?

A

Custom log locations can be assigned for Nginx web server for different Virtual Host.

Q

In Centos what is the default nginx configuration file?

A

On Centos the default nginx configuration file is # vim /etc/nginx/conf.d/virtual.conf

Q

Why Nginx is faster than Apache?

A

Nginx can serve more requests per second than Apache on the same hardware.

Q

What is the difference between Proxy and Nginx Reverse Proxy?

A

Differences Between Forward Proxy and Reverse Proxy. The main difference between the two is that forward proxy is used by the client such as a web browser whereas reverse proxy is used by the server such as a web server. Forward proxy and the client can be in the same internal network, or it can be on the Internet.

Related Tutorials in How to Configure Nginx Virtualhost in FreeBSD

Related Tutorials in How to Configure Nginx Virtualhost in FreeBSD

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 squid proxy server on freeBSD
How to install squid proxy server on freeBSD
Feb 10, 2017
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 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
How to change Default Document root of Nginx Webserver
How to change Default Document root of Nginx Webserver
May 8, 2017

Related Forums in How to Configure Nginx Virtualhost in FreeBSD

Related Forums in How to Configure Nginx Virtualhost in FreeBSD

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
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
Nginx
akshin class=
Cannot see location = /nginx in backend servers
Jan 8, 2020
Nginx
gibbson class=
How do i run both nginx and apache in same instance on centos
Sep 6, 2017
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 David Lopez Guillen ?
Ayuda urgente instale SSL para servidor Opensuse y ahora no funciona tengo servicio web

hola segui este tutorial para tener un certificado ssl y ahora no se ve mi app en la red, espero alguien pueda ayudarme, tengo M9oodle en3.5 en un servidor open suse y ahora no funciona por favor ayuda.

https://www.linuxhelp.com/how-to-create-ssl-certificate-in-opensuse

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.