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

## Introduction  <a href="#introduction" id="introduction"></a>

Owning a [personal web server](https://nordvpn.com/cybersecurity/glossary/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](https://www.nginx.com/resources/glossary/nginx/). It is free, open-source software that allows you to build and self-host websites. It can also function as a [reverse proxy](https://meshnet.nordvpn.com/how-to/remote-access/custom-host-names-using-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](https://nordvpn.com/blog/what-is-lan/) (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 ](https://nordvpn.com/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](https://meshnet.nordvpn.com/features/linking-devices-in-meshnet).

Even though the NGINX web server can be run as a [Docker container](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/), 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 <a href="#configure-a-web-server-on-windows" id="configure-a-web-server-on-windows"></a>

In this part of the article, you can find instructions on how to configure the NGINX web server.

{% tabs %}
{% tab title="Windows" %}

### Set up NGINX

To start setting up the web server, you will need to install NGINX.

1. Go to the [NGINX download page](http://nginx.org/en/download.html) and download the latest mainline version for Windows.&#x20;
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.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fo5alwFwCpRmIqrcJjeQZ%2Fnginx_win_conf_dark.png?alt=media&#x26;token=bb7f7a11-d840-4fd0-ac83-94b4702a8a6d" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FFB3CcKeAPugexWtfpaZG%2Fnginx_win_conf.png?alt=media&#x26;token=e38a47d9-dbf6-4d7a-a49d-1240aedf8296" alt="nginx.conf file highlighted in the NGINX folder."></picture><figcaption></figcaption></figure></div>

   &#x20;
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.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FhuDm8kRlluOMuPAVDIx9%2Fnginx_win_listen.png?alt=media&#x26;token=b35a2e8d-c9ca-4211-a5a8-c5e51a8f0043" alt="Section of the nginx.conf file containing the port number highlighted."><figcaption></figcaption></figure></div>

   &#x20;
7. Save changes (**File** > **Save**) and exit.

{% hint style="info" %}
**Note**

If you do not change the [port number](https://nordvpn.com/blog/what-is-my-port/) 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`
{% endhint %}

### Control NGINX <a href="#control-nginx" id="control-nginx"></a>

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

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FuLoGztEDtfGvyYMNH64Q%2Fnginx_win_path.png?alt=media&#x26;token=09c5f582-2ff9-4464-a3e8-a0fa602779bb" alt="Full path of the NGINX folder highlighted. " width="375"><figcaption></figcaption></figure></div>

   &#x20;
3. Open the Windows Command Prompt by pressing the **Windows** <img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FGTHMj8B4fgledLDhPDUm%2Ficon_win_start_11_blue.svg?alt=media&#x26;token=045c5a29-141c-44c1-9dfa-08d59d6bf047" alt="" data-size="line"> 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.\
   &#x20;\
   **Example**

   ```bash
   cd "C:\Users\meshnet\Desktop\nginx-1.27.1\"
   ```

   &#x20;\
   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.\
   &#x20;\
   To check if the web server started, open an internet browser of your choice and enter `localhost` in the URL bar. If the setup is correct, you will be greeted with the default NGINX landing page.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FwG9JMDYBRY6oJMWeDgqX%2Fnginx_win_access_dark.png?alt=media&#x26;token=a4848597-e297-43d7-985e-254d3a78e38d" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FhUOpHYbKTkGlrCiveri5%2Fnginx_win_access.png?alt=media&#x26;token=a83c9deb-f5eb-4e36-8228-0de31e9f9750" alt="NGINX landing page visible after visiting localhost on an internet browser."></picture><figcaption></figcaption></figure></div>

{% hint style="info" %}
**Note**

If the **Windows security alert** box appears, select both the *private* and *public* networks options, and then click the **Allow access** button to allow incoming connections through the firewall.

![](https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FbpKayZlQeobnagjjzldx%2Fnginx_win_fw.png?alt=media\&token=ea585375-8167-49e8-b7aa-fecbf015c7b6)
{% endhint %}

{% hint style="info" %}
**Note**

You won't 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 should open a new command prompt window and navigate to the NGINX directory once again.
{% endhint %}

### Personalize your landing page <a href="#personalize-your-landing-page" id="personalize-your-landing-page"></a>

You can make adjustments to the landing page 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:\
   &#x20;

   ```bash
   nginx.exe -s reload
   ```

Lastly, visit `localhost` in your web browser once again to see the newly designed website.

{% hint style="info" %}
**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.&#x20;

To resolve this problem, [clear your cache](https://nordvpn.com/blog/how-to-clear-your-cache/) and try accessing the website once more.
{% endhint %}
{% endtab %}

{% tab title="macOS" %}
{% hint style="info" %}
**Note**

Homebrew is compatible with macOS Big Sur (Version 11) or later.

For this configuration, macOS Sonoma (Version 14.6.1) with an Intel processor was used.
{% endhint %}

### Install Homebrew

To install NGINX, you can use the [Homebrew](https://brew.sh/) package manager. Install Homebrew by taking these steps:

1. Open Terminal.
2. Enter the following command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
   </code></pre>

   &#x20;\
   For additional information about the installation process, refer to [Homebrew documentation](https://docs.brew.sh/Installation).
3. Follow the on-screen instructions to finish the installation.

With Homebrew installed, you can proceed with installing NGINX.

### Install NGINX <a href="#install-nginx" id="install-nginx"></a>

To install NGINX using Homebrew, follow these steps:

1. Open **Terminal** and run the following command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">brew install nginx
   </code></pre>

   &#x20;
2. Wait for Homebrew to download and install NGINX with all of the required dependencies.

### Change the configuration file <a href="#change-the-configuration-file" id="change-the-configuration-file"></a>

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.

<div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FmGFVLSSH44GDCcfX4rH4%2Fnginx_mac_port_dark.png?alt=media&#x26;token=24ea59a8-2cf2-4123-9ab7-e88d60cf191a" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FP6bsRUCsdt4Abgr4yEiA%2Fnginx_mac_port.png?alt=media&#x26;token=fffd3235-ea91-4a15-963f-3d37b6c3ba48" alt="Port 8080 highlighted in the NGINX installation output"></picture><figcaption></figcaption></figure></div>

To change the port number for the NGINX web server, do the following:

1. Open the `nginx.conf` file using the Nano text editor by running this command in **Terminal**:\
   &#x20;\
   For Intel Macs:

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nano /usr/local/etc/nginx/nginx.conf
   </code></pre>

   &#x20;\
   For [Apple silicon Macs](https://support.apple.com/en-us/HT211814):

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nano /opt/homebrew/etc/nginx/nginx.conf
   </code></pre>

   &#x20;
2. Locate the `listen` line and change the number next to it from 8080 to 80.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FWjKNoUmIACPVCCIxIeAC%2Fnginx_mac_listen_dark.png?alt=media&#x26;token=e85db934-381e-422a-b87e-a4ca54ea071d" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FJ1YUKUQ4TQeuHNCmurS6%2Fnginx_mac_listen.png?alt=media&#x26;token=fc6c7302-39a3-448b-9494-4e570dfac43e" alt="nginx.conf file section indicating the port number."></picture><figcaption></figcaption></figure></div>

   &#x20;
3. Press **Control** + **X**, **Y**, and **Return** to save changes and exit.
4. Run the following command to restart the NGINX service:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">brew services restart nginx
   </code></pre>

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.

<div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fp9kjBmp0yDpn2W6VpQ0n%2Fnginx_mac_access_dark.png?alt=media&#x26;token=13527bf1-d5f7-4155-b300-64a1b9667638" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FWh5R6x6FNLwHvQ8mMhUc%2Fnginx_mac_access.png?alt=media&#x26;token=8954da75-d01c-43f9-9190-6bab969f6b17" alt="NGINX landing page visible after visiting localhost on an internet browser."></picture><figcaption></figcaption></figure></div>

{% hint style="info" %}
**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 you leave the default port 8080, you would need to enter the following in your internet browser:\
`localhost:8080`
{% endhint %}

### Personalize your landing page <a href="#personalize-your-landing-page.1" id="personalize-your-landing-page.1"></a>

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.

1. Open **Terminal** and run the following command:\
   &#x20;\
   For Intel Macs:

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nano /usr/local/var/www/index.html
   </code></pre>

   &#x20;\
   For [Apple silicon Macs](https://support.apple.com/en-us/HT211814):

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nano /opt/homebrew/var/www/index.html
   </code></pre>

   &#x20;
2. Make any necessary changes to the file using HTML.
3. After modifying the file, press **Control** + **X**, **Y**, and **Return** to save changes and exit.
4. Run the following command to restart the NGINX service:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">brew services restart nginx
   </code></pre>

   &#x20;\
   Enter your user password, if prompted.

Lastly, visit `localhost` in your web browser once again to see the newly designed website.

{% hint style="info" %}
**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.&#x20;

To resolve this problem, [clear your cache](https://nordvpn.com/blog/how-to-clear-your-cache/) and try accessing the website once more.
{% endhint %}
{% endtab %}

{% tab title="Linux" %}
{% hint style="info" %}
**Note**

For this configuration, Ubuntu 24.04.1 LTS was used.
{% endhint %}

### Set up NGINX <a href="#set-up-nginx.1" id="set-up-nginx.1"></a>

To start setting up the web server, you need to install NGINX.

1. Update all of your repositories and install NGINX by running the following command in **Terminal**:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo apt update &#x26;&#x26; sudo apt install nginx -y
   </code></pre>

   &#x20;
2. Once the installation finishes, run the following command to open the NGINX configuration file using the Nano text editor.\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nano /etc/nginx/sites-available/default
   </code></pre>

   &#x20;\
   For other Linux distributions, use this command:

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nano /etc/nginx/nginx.conf
   </code></pre>

   &#x20;
3. Locate the `listen` line and ensure that the number next to it is set to 80.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F1tCPwEzotmCDLUH48lIL%2Fnginx_linux_listen.png?alt=media&#x26;token=f86dec00-fca0-41bb-8eb6-7e03a93e98a2" alt="Section of the default file indicating the port number used by NGINX."><figcaption></figcaption></figure></div>

   &#x20;\
   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.

<div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F3DfEOKSvqJ624mLd0VCJ%2Fnginx_linux_access_dark.png?alt=media&#x26;token=6325fbb7-bb95-4d7c-8ff6-7d9b8daca3bd" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fxzrt2Gz4wbwd0kQaIcCx%2Fnginx_linux_access.png?alt=media&#x26;token=01cb750d-5489-40c0-b690-3b21a4db1480" alt="NGINX landing page visible after visiting localhost on an internet browser."></picture><figcaption></figcaption></figure></div>

{% hint style="info" %}
**Note**

If you do not change the [port number](https://nordvpn.com/blog/what-is-my-port/) to port 80, you will be required to specify the port from the `/etc/nginx/sites-available/default` 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`
{% endhint %}

### 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:

{% code overflow="wrap" %}

```bash
nginx: [emerg] bind() to failed (98: Address already in use)
nginx: [emerg] bind() to failed (98: Unknown error)
```

{% endcode %}

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:

{% code overflow="wrap" %}

```bash
sudo netstat -tulpn | grep :80
```

{% endcode %}

{% hint style="info" %}
**Note**

The `net-tools` package is required to use the `netstat` command.

It can be installed by executing the following command:

```bash
sudo apt install net-tools
```

{% endhint %}

In 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>`.&#x20;

**Example**

{% code overflow="wrap" %}

```bash
sudo kill 2059
```

{% endcode %}

<div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FWWOpCrwXqm6sK3suBIbo%2Fkill_process.png?alt=media&#x26;token=f48fbdd0-09bb-488a-86bc-05273937cbef" alt="Terminal output showing processes that are using port 80."><figcaption></figcaption></figure></div>

Alternatively, you can either change the port of NGINX or the port of the other service.

### Personalize your landing page <a href="#personalize-your-landing-page.2" id="personalize-your-landing-page.2"></a>

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.

1. Open the `index.nginx-debian.html` file using the Nano text editor by running this command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nano /var/www/html/index.nginx-debian.html
   </code></pre>

   &#x20;\
   If you do not have the `index.nginx-debian.html` file, use the following command to find the necessary .html file on your system.\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">ls /var/www/html
   </code></pre>

   &#x20;
2. Make any necessary changes to the file using HTML.
3. After modifying the file, press **Ctrl** + **X**, **Y**, and **Enter** to save changes and exit.
4. If NGINX is still running, run the following command to restart it with the new change:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nginx -s reload
   </code></pre>

   &#x20;\
   Otherwise, you can start NGINX by running the `sudo nginx` command.

Lastly, visit `localhost` in your web browser once again to see the newly designed website.

{% hint style="info" %}
**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.&#x20;

To resolve this problem, [clear your cache](https://nordvpn.com/blog/how-to-clear-your-cache/) and try accessing the website once more.
{% endhint %}
{% endtab %}
{% endtabs %}

## Access the web server using Meshnet <a href="#access-the-web-server-using-meshnet" id="access-the-web-server-using-meshnet"></a>

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**.\
   &#x20;\
   **Example**

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F26fJTwHibNm2ZvrCCUuG%2Fnginx_remote_access_dark.png?alt=media&#x26;token=7f7f30ff-9add-4452-82fa-2bf1d4cab03c" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FqV7LqeoEzsLugbEWR54O%2Fnginx_remote_access.png?alt=media&#x26;token=bcb396f1-4b0b-40cd-b0b2-728fb0e66225" alt="Custom NGINX website showing after entering the Nord name to the URL bar."></picture><figcaption></figcaption></figure></div>
