Nginx Ubuntu Access Virtual Host From Another Machine Over Lan

Nginx Ubuntu Access Virtual Host From Another Machine Over LAN

Are you trying to access a virtual host set up using Nginx on Ubuntu from another machine over a LAN? Well, this article is for you! In this article, we will go over the steps you need to take to access your virtual host from another machine over a LAN. But before we get into that, let’s talk a bit about Nginx and Ubuntu.

Nginx is a web server software designed to handle large amounts of traffic. It is known for its high performance, stability, and low resource usage. Ubuntu, on the other hand, is an open-source operating system based on the Linux kernel. It is widely used in web hosting, cloud computing, and server setups due to its stability, security, and ease of use.

Now, let’s get into the main topic of this article, which is accessing a virtual host set up using Nginx on Ubuntu from another machine over a LAN.

Step 1: Set Up a Virtual Host on Nginx

The first step is to set up a virtual host on Nginx. This can be easily done by creating a new configuration file in the ‘/etc/nginx/sites-available/’ directory. This directory contains all the configuration files for virtual hosts on Nginx. Here’s an example configuration file:

server {
listen 80;
server_name example.com;
root /var/www/example.com/public_html;
index index.html index.htm;
}

The above configuration file sets up a virtual host for example.com. The ‘listen’ directive specifies the port on which the virtual host will listen. The ‘server_name’ directive specifies the domain name of the virtual host. The ‘root’ directive specifies the root directory of the virtual host, and the ‘index’ directive specifies the default file to be served.

After creating the configuration file, enable the site by creating a symbolic link in the ‘/etc/nginx/sites-enabled/’ directory. Use the following command:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Now restart Nginx using the command:

sudo systemctl restart nginx

Step 2: Configure Firewall

The next step is to configure the firewall to allow incoming traffic on port 80. Use the following command to allow incoming traffic on port 80:

sudo ufw allow 80/tcp

This command allows TCP traffic on port 80, which is the default port for HTTP traffic.

Step 3: Configure Hosts File

The next step is to configure the hosts file on the machine you want to access the virtual host from. Open the ‘/etc/hosts’ file using a text editor and add the following line:

192.168.0.10 example.com

In the above line, replace ‘192.168.0.10’ with the IP address of the machine hosting the virtual host, and ‘example.com’ with the domain name of the virtual host.

Step 4: Access Virtual Host from Another Machine Over LAN

Now you can access the virtual host from another machine over the LAN by opening a web browser and entering the domain name of the virtual host in the address bar. For example, if the virtual host is set up for ‘example.com’, enter ‘http://example.com’ in the address bar of the web browser.

Conclusion

In conclusion, accessing a virtual host set up using Nginx on Ubuntu from another machine over a LAN is a simple process that involves setting up a virtual host on Nginx, configuring the firewall, configuring the hosts file, and accessing the virtual host using a web browser. By following the steps outlined in this article, you should be able to access your virtual host from another machine over a LAN in no time.

Leave a Reply

Your email address will not be published. Required fields are marked *