• 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 Virtualhost in FreeBSD

{{postValue.id}}

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
{{postCtrl.cmtErrMsg}}

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.

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 Ryan ?
how to use visual traceroute tool

Am using traceroute command to check for the route. i got this tool while surfing. So pls help me out installation and usage of Visual traceroute tool.

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.