How to set up an NGINX web server and access it over Meshnet

Learn how to set up a self-hosted web server using NGINX on Windows, macOS, and Linux and access it over Meshnet.

Introduction

Owning a personal website is a dream that many people have. However, the more you look into it, the scarier it may seem: spending money on hosting, purchasing a domain name, and finding the best foundation. Nonetheless, in most cases, it is much more convenient to develop the web server on your personal machine since you have full access and control over your project. Self-hosting saves both time and money since you do not have to pay for hosting while the site is still in development. Additionally, the project can be shared with others by granting them access to your machine.

A tool that is widely used for configuring self-hosted websites is NGINX. It is free, open-source software that allows you to build and run self-hosted web servers. However, the drawback of such a setup is that, without poking holes in your firewall, the server can only be reached from the same local network. 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 in a Docker container, this guide will focus on the standard setup process. You will learn how to configure a simple, self-hosted HTML web server and reach it remotely 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.

  1. Go to the NGINX download page and download the latest mainline version for Windows.

  2. Extract the downloaded archive.

  3. Move the extracted folder to a convenient location, for example, the desktop.

  4. Go inside the NGINX folder, open the conf folder, and locate the nginx.conf file.

    nginx.conf file highlighted in the NGINX folder.

  5. Open the nginx.conf file using a text editor, such as Notepad.

  6. Locate the listen line and ensure that the number next to it is set to 80.

    Section of the nginx.conf file containing the port number highlighted.

  7. Save changes (File > Save) and exit.

Note

If you do not change the port number to port 80, you will be required to specify the port from the nginx.conf file when accessing the website.

For example, if the port is set to 8080, you would need to enter the following in your internet browser: localhost:8080

Control NGINX

You can control NGINX services by using the command line. Commands allow you to start, stop, and restart NGINX.

  1. Locate the nginx.exe file in the NGINX folder, right-click it, and choose Properties.

  2. Copy its full path, which is displayed next to Location.

  3. Open the Windows Command Prompt by pressing the Windows key + R on your keyboard, typing in cmd, and pressing Enter.

  4. In the Command Prompt window, enter cd and paste in the copied path surrounded by quotation marks. Example

    cd "C:\Users\secretmeerkat\Desktop\nginx-1.23.3\"

    Now, you can control the nginx.exe file using the Command Prompt.

  5. Type in nginx.exe and press Enter to start the web server. To check if the web server started, open an internet browser of your choice and enter localhost in the URL bar. If the setup was correct, you will be greeted with the default NGINX landing page.

    NGINX landing page visible after visiting localhost on an internet browser.

Note

You will not be able to run any other commands in the same Command Prompt that was used to start NGINX. To run any new NGINX-related commands, you will need to open a new command prompt window and go to the NGINX directory once again.

Personalize your landing page

You can make adjustments to the landing page in order to customize the website to your preference.

  1. In the NGINX folder, open the html folder, and locate the index.html file.

  2. Open index.html using a text editor, such as Notepad.

  3. Make any necessary changes to the file using HTML.

  4. Save changes (File > Save) and exit.

  5. 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.

Note

The initial iteration of the web server may still be visible in the browser after reloading the NGINX server. This is because it is saved in the browser’s cache.

To resolve this problem, clear your cache and try accessing the website once more.

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.

  1. Copy the NGINX server device's Nord name from the NordVPN application.

  2. Open your internet browser.

  3. Paste the copied Nord name followed by a slash (/) to the URL field and press Enter. Example secret.meerkat-andes.nord/

    Custom NGINX website showing after entering the Nord name to the URL bar.

Last updated

Was this helpful?

#585: Articles | Mumble, Airsonic, Rocket.Chat

Change request updated