FreeBSD: Nginx Virtual Hosting Configuration

h‮‬ttps://www.lautturi.com
FreeBSD: Nginx Virtual Hosting Configuration

To configure virtual hosting with Nginx on a FreeBSD system, you will need to do the following:

  1. Install Nginx on the system.

  2. Create a directory for each virtual host. This can be done using the mkdir command.

For example, to create a directory for a virtual host named example.com, you can run the following command:

# mkdir -p /usr/local/www/nginx/example.com
  1. Create a configuration file for each virtual host in the /usr/local/etc/nginx/vhosts directory.

For example, to create a configuration file for the example.com virtual host, you can create a file named example.com in the /usr/local/etc/nginx/vhosts directory with the following contents:

server {
    listen 80;
    server_name example.com;
    root /usr/local/www/nginx/example.com;
}

This will configure Nginx to listen for HTTP requests on port 80 for the example.com virtual host and serve the content from the /usr/local/www/nginx/example.com directory.

  1. Edit the nginx.conf file in the /usr/local/etc/nginx directory to include the virtual host configuration files.

For example, you can add the following lines to the nginx.conf file:

include vhosts/*;

This will include all the configuration files in the /usr/local/etc/nginx/vhosts directory in the Nginx configuration.

  1. Restart Nginx to apply the changes.

For example, to restart Nginx, you can run the following command:

# service nginx restart

After Nginx has been restarted, it should be configured to serve content for the virtual hosts you have configured.

For more information about configuring virtual hosting with Nginx on a FreeBSD system, you can refer to the Nginx documentation and the nginx man page by running man nginx on the command line.

Created Time:2017-10-28 20:40:39  Author:lautturi