How to set up an NGINX web server and remotely access it over Meshnet
Learn how to configure an NGINX web server on Windows, macOS, and Linux and remotely access it using Meshnet.
Introduction
Owning a personal web server is a dream many people have. Self-hosting a website grants you complete control over its configuration during all development stages and enhances data privacy because the information does not leave your infrastructure.
A tool that is widely used for configuring web servers is NGINX. It is free, open-source software that allows you to build and self-host websites. It can also function as a reverse proxy. However, the drawback of such a setup is that, without poking holes in your firewall, the server can only be accessed from the same local area network (LAN). Having a commonly used port exposed to the outside world is dangerous because it can be scanned and probed for vulnerabilities by attackers.
This is where Meshnet comes to your aid. By using Meshnet, you can have a secure and encrypted tunnel from end devices to your web server without any custom configurations. The website can also be accessed by your friends or family, which you have as your Meshnet peers.
Even though the NGINX web server can be run as a Docker container, this guide will focus on the standard setup process. You will learn how to configure a simple HTML web server and remotely access it from other devices using Meshnet.
Configure a web server
In this part of the article, you can find instructions on how to configure the NGINX web server.
Set up NGINX
To start setting up the web server, you will need to install NGINX.
Go to the NGINX download page and download the latest mainline version for Windows.
Extract the downloaded archive.
Move the extracted folder to a convenient location — for example, the desktop.
Go inside the NGINX folder, open the conf folder, and locate the nginx.conf file.


Open the nginx.conf file using a text editor, such as Notepad.
Locate the
listenline and ensure that the number next to it is set to 80.
Save changes (File > Save) and exit.
Control NGINX
You can control NGINX services by using the command line. Commands allow you to start, stop, and restart NGINX.
Locate the nginx.exe file in the NGINX folder, right-click it, and choose Properties.
Copy its full path, which is displayed next to Location.

Open the Windows Command Prompt by pressing the Windows
key + R on your keyboard, typing in
cmd, and pressing Enter.In the Command Prompt window, enter
cdand paste in the copied path surrounded by quotation marks. Examplecd "C:\Users\meshnet\Desktop\nginx-1.27.1\"Now, you can control the nginx.exe file using the Command Prompt.
Type in
nginx.exeand press Enter to start the web server. To check if the web server started, open an internet browser of your choice and enterlocalhostin the URL bar. If the setup is correct, you will be greeted with the default NGINX landing page.

Personalize your landing page
You can make adjustments to the landing page to customize the website to your preference.
In the NGINX folder, open the html folder and locate the index.html file.
Open index.html using a text editor, such as Notepad.
Make any necessary changes to the file using HTML.
Save changes (File > Save) and exit.
In the command prompt, run the following command to reload NGINX with the new configuration:
nginx.exe -s reload
Lastly, visit localhost in your web browser once again to see the newly designed website.
Install Homebrew
To install NGINX, you can use the Homebrew package manager. Install Homebrew by taking these steps:
Open Terminal.
Enter the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"For additional information about the installation process, refer to Homebrew documentation.
Follow the on-screen instructions to finish the installation.
With Homebrew installed, you can proceed with installing NGINX.
Install NGINX
To install NGINX using Homebrew, follow these steps:
Open Terminal and run the following command:
brew install nginxWait for Homebrew to download and install NGINX with all of the required dependencies.
Change the configuration file
By default, the NGINX port will be set to 8080. However, you can change it to port 80 to allow easier access to the web server via Meshnet.


To change the port number for the NGINX web server, do the following:
Open the
nginx.conffile using the Nano text editor by running this command in Terminal: For Intel Macs:nano /usr/local/etc/nginx/nginx.confFor Apple silicon Macs:
nano /opt/homebrew/etc/nginx/nginx.confLocate the
listenline and change the number next to it from 8080 to 80.

Press Control + X, Y, and Return to save changes and exit.
Run the following command to restart the NGINX service:
brew services restart nginx
With the service restarted, open an internet browser of your choice and enter localhost in the URL bar. If the setup is successful, you will be greeted with the default NGINX landing page.


Personalize your landing page
Now you should have the web server up and running. You can make adjustments to the landing page to customize the website to your preference.
Open Terminal and run the following command: For Intel Macs:
nano /usr/local/var/www/index.htmlFor Apple silicon Macs:
nano /opt/homebrew/var/www/index.htmlMake any necessary changes to the file using HTML.
After modifying the file, press Control + X, Y, and Return to save changes and exit.
Run the following command to restart the NGINX service:
brew services restart nginxEnter your user password, if prompted.
Lastly, visit localhost in your web browser once again to see the newly designed website.
Set up NGINX
To start setting up the web server, you need to install NGINX.
Update all of your repositories and install NGINX by running the following command in Terminal:
sudo apt update && sudo apt install nginx -yOnce the installation finishes, run the following command to open the NGINX configuration file using the Nano text editor.
sudo nano /etc/nginx/sites-available/defaultFor other Linux distributions, use this command:
sudo nano /etc/nginx/nginx.confLocate the
listenline and ensure that the number next to it is set to 80.
If you do make any changes, press Ctrl + X, Y, and Enter to save and exit.
Now, open your internet browser and enter localhost into the URL bar. If the setup was correct, you will be greeted with the default NGINX landing page.


How to fix error 98
The most common error that you can encounter while trying to start NGINX is error 98. It may come with either of the following messages:
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Unknown error)If you receive this error, you will not be able to finish the configuration without resolving it.
To fix the error, find what service is using the required port (for example, port 80) by running the following command:
sudo netstat -tulpn | grep :80In the output, you will see the name of the process and its process identification number (PID). With that information, you can kill the process by using sudo kill <PID>.
Example
sudo kill 2059
Alternatively, you can either change the port of NGINX or the port of the other service.
Personalize your landing page
Now you should have the web server up and running. You can make adjustments to the landing page to customize the website to your preference.
Open the
index.nginx-debian.htmlfile using the Nano text editor by running this command:sudo nano /var/www/html/index.nginx-debian.htmlIf you do not have the
index.nginx-debian.htmlfile, use the following command to find the necessary .html file on your system.ls /var/www/htmlMake any necessary changes to the file using HTML.
After modifying the file, press Ctrl + X, Y, and Enter to save changes and exit.
If NGINX is still running, run the following command to restart it with the new change:
sudo nginx -s reloadOtherwise, you can start NGINX by running the
sudo nginxcommand.
Lastly, visit localhost in your web browser once again to see the newly designed website.
Access the web server using Meshnet
Once the web server is up and running, you can reach it remotely via Meshnet from your peer devices.
Copy the NGINX server device's Nord name from the NordVPN application.
Open your internet browser.
Paste the copied Nord name followed by a slash (/) to the URL field and press Enter. Example


Last updated
Was this helpful?
