# Reversed Proxy & Web Secure Socket It's useful to put your Nym Node behind a reversed proxy and have it accessible via `https` domain, where you can host a [landing page](../legal/landing-pages.md). The guide is right [below](#reversed-proxy). More advanced and secure solution is to have your node behind Web Secure Socket (WSS). Follow this [this guide](#web-secure-socket-setup) for installation. ```admonish info For both of these configurations you will need to register a DNS domain and configure a record to your VPS. ``` ## Variables Explanation This guide contains several variables. Substitute them with your own value, without `<>` brackets. Here is a list of variables we used below. | Variable | Description | Syntax example | | :--- | :--- | :--- | | `` | Your registered DNS domain, asigned to the VPS with `nym-node` | exit-gateway1.squad.nsl | | `` | Port listening to WSS, default is `9001` | 9001 | | `` | Any text you want to show on the landing page | Welcome to Nym Node, operator contact is example@email.me | | `` | A sub-directory located at `/var/www/` containing html configuration files | `/var/www/exit-gateway1.squad.nsl` | | `` | A local only `nym-node` identifier, specified by flag `--id`, default is `default-nym-node` | alice_super_node | | `` | Specify a full path to the given file, directory or binary behind this variable | `/root/src/nym/target/release/` | ```admonish warning title="" The commands in this setup need to be run with root permission. Either add a prefix `sudo` or execute them from a root shell. ``` ## Reversed Proxy Setup ```admonish info This guide was created by a Nym node operator, [Avril 14th](https://avril14th.org) as a part of [Nym Operators Community Counsel](../legal/community-counsel.md), edited by Nym. ``` The following snippet needs be modified as described below according to the public identity that you may want to show on this public notice, i.e. your graphics and your email. It would allow you to serve it as a landing page resembling the one proposed by [Tor](https://gitlab.torproject.org/tpo/core/tor/-/raw/HEAD/contrib/operator-tools/tor-exit-notice.html) but with all the changes needed to adhere to the Nym's operators case. ### HTML File Customization File for html configuration are by convention located at `/var/www/` directory and it's subdirectories. We refer to this directory as ``. 1. Start by creating this directory: ```sh mkdir -p /var/www/ ``` 2. Use your own html code or copy the template below to a new file called `index.html` located in `/var/www/` directory. ~~~admonish example collapsible=true title="An example template for `/var/www//index.html` page" ```html This is a NYM Exit Gateway

This is a NYM Exit Gateway

You are most likely accessing this website because you've had some issue with the traffic coming from this IP. This router is part of the NYM project, which is dedicated to create outstanding privacy software that is legally compliant without sacrificing integrity or having any backdoors. This router IP should be generating no other traffic, unless it has been compromised.

The Nym mixnet is operated by a decentralised community of node operators and stakers. The Nym mixnet is trustless, meaning that no parts of the system nor its operators have access to information that might compromise the privacy of users. Nym software enacts a strict principle of data minimisation and has no back doors. The Nym mixnet works by encrypting packets in several layers and relaying those through a multi-layered network called a mixnet, eventually letting the traffic exit the Nym mixnet through an exit gateway like this one. This design makes it very hard for a service to know which user is connecting to it, since it can only see the IP-address of the Nym exit gateway:

Illustration showing how a user might connect to a service through the Nym network. The user first sends their data through three daisy-chained encrypted Nym nodes that exist on three different continents. Then the last Nym node in the chain connects to the target service over the normal internet. The user This server Your service Nym network link Unencrypted link

Read more about how Nym works.

Nym relies on a growing ecosystem of users, developers and researcher partners aligned with the mission to make sure Nym software is running, remains usable and solves real problems. While Nym is not designed for malicious computer users, it is true that they can use the network for malicious ends. This is largely because criminals and hackers have significantly better access to privacy and anonymity than do the regular users whom they prey upon. Criminals can and do build, sell, and trade far larger and more powerful networks than Nym on a daily basis. Thus, in the mind of this operator, the social need for easily accessible censorship-resistant private, anonymous communication trumps the risk of unskilled bad actors, who are almost always more easily uncovered by traditional police work than by extensive monitoring and surveillance anyway.

In terms of applicable law, the best way to understand Nym is to consider it a network of routers operating as common carriers, much like the Internet backbone. However, unlike the Internet backbone routers, Nym mixnodes do not contain identifiable routing information about the source of a packet and do mix the user internet traffic with that of other users, making communications private and protecting not just the user content but the metadata (user's IP address, who the user talks to, when, where, from what device and more) and no single Nym node can determine both the origin and destination of a given transmission.

As such, there is little the operator of this Exit Gateway can do to help you track the connection further. This Exit Gateway maintains no logs of any of the Nym mixnet traffic, so there is little that can be done to trace either legitimate or illegitimate traffic (or to filter one from the other). Attempts to seize this router will accomplish nothing.

To decentralise and enable privacy for a broad range of services, this Exit Gateway adopts an Exit Policy in accordance with the Tor Null ‘deny’ list and the Tor reduced policy, which are two established safeguards.

That being said, if you still have a complaint about the router, you may email the maintainer. If complaints are related to a particular service that is being abused, the maintainer will submit that to the NYM Operators Community in order to add it to the Exit Policy cited above. If approved, that would prevent this router from allowing that traffic to exit through it. That can be done only on an IP+destination port basis, however. Common P2P ports are already blocked.

You also have the option of blocking this IP address and others on the Nym network if you so desire. The Nym project provides a web service to fetch a list of all IP addresses of Nym Gateway Exit nodes that allow exiting to a specified IP:port combination. Please be considerate when using these options.

``` ~~~ 3. Before you save and close the file, make sure to edit the text, especially the information in these points: - Add your favicon logo on the line: ``` ``` - Add your header logo on the line: ``` ``` - By either setting the URl to the image (if you're hosting it publicly, i.e. on your web server) ``` href="" # and src="" ``` - **or** by adding the image inline as base64 encoded image ``` href="href="data:image/x-icon;base64,AAABAAMA...."" # and src="href="data:image/x-icon;base64,AAABAAMA...."" ``` - Add the email address you're willing to use for being contacted. ``` maintainer ``` - If you're running the node within the US check the sections marked as `FIXME`, add your DNS name and un-comment those. 4. Save and exit Now your html page is configured. ### `nym-node` Configuration When done with the customization, you'll need to make sure your `nym-node` uploads the file and reference to it. This is done by opening your node configuration file located at `~/.nym/nym-nodes//config/config.toml` and changing the value of the line `landing_page_assets_path` on the `[http]` section: ``` landing_page_assets_path = '' ``` ### Reverse Proxy Configuration You may set up a [reverse proxy](https://www.nginx.com/resources/glossary/reverse-proxy-server/) in order to serve this landing page with proper SSL and DNS management, i.e. to resolve it to https://. The following assumes that you're owning a domain and that you've already set the Let's Encrypt certificates on your hosting, and you've copied those on your Gateway, i.e. copy the two Let's Encript pem files on your Gateway's home folder. Else you may obtain a Let's Encrypt certificate using a [`--certonly` procedure](https://eff-certbot.readthedocs.io/en/latest/using.html#getting-certificates-and-choosing-plugins). **Configure Nginx** 1. Install `nginx`: ```sh sudo apt install nginx ``` 2. Setup firewall with `ufw`. `ufw` has three profile pre-configured for `nginx`, we will need the first one for `nym-node`: - `Nginx Full`: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic) - `Nginx HTTP`: This profile opens only port 80 (normal, unencrypted web traffic) - `Nginx HTTPS`: This profile opens only port 443 (TLS/SSL encrypted traffic) ```sh ufw allow 'Nginx Full' # you can verify by ufw status # possibly reload ufw by ufw reload ``` 3. Disable the default Nginx landing page ``` systemctl status nginx unlink /etc/nginx/sites-enabled/default systemctl restart nginx ``` 4. Add your endpoint configuration to Nginx by creating file: ```sh nano /etc/nginx/sites-available/ ``` - and changing `` occurrences below with your domain name: ``` server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name nym-exit.; ssl_certificate /etc/letsencrypt/live//fullchain.pem; ssl_certificate_key /etc/letsencrypt/live//privkey.pem; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; listen [::]:80; if ($host = ) { return 301 https://$host$request_uri; } server_name www.; return 301 https://$request_uri; } ``` 5. Activate the configuration by creating a simlink to `/etc/nginx/sites-enabled`: ```sh ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled ``` 6. Test your configuration syntax: ```sh nginx -t ``` 7. Restart `nginx`: ```sh systemctl daemon-reload && systemctl restart nginx ``` 8. Get an `SSL` certificate using certbot: ```sh apt install certbot python3-certbot-nginx certbot renew --dry-run certbot --nginx -d ``` 9. Restart your `nym-node` or if you're running your `nym-node` as a [`systemd` service](configuration.md#systemd), restart your service: ```sh systemctl daemon-reload service nym-node restart ``` 10. Check for the page being served reading the service logs ```sh journalctl -u nym-gateway.service | grep 8080 # where you should see ... Started NymNodeHTTPServer on 0.0.0.0:8080 ``` Now your `nginx` should be configured, up and running. Test it by inserting your `` as a URL in a browser. ## Web Secure Socket Setup For better security of transfered data, we recommend node operators to run their nodes through Secure Socket instead of be out in open. You can read more about *Secure Socket Layer* (SSL) in [here](https://www.geeksforgeeks.org/secure-socket-layer-ssl/). Before you start, don't forget to register a DNS and configure a record for your VPS with `nym-node`. If you haven't configure reversed proxy before, start with [*Preliminary steps* chapter](#preliminary-steps) below and only then move to WSS setup. If you have reversed proxy already running and your `nym-node` can be reached via https, you can skip *Preliminary steps* and begin to setup WSS directly. Remember that there may be some unique variables and customization depending on the way your reversed proxy is done which you may have to adjust when installing WSS in order to make it work. ```admonish tip To see description of used variables (noted in `<>` brackets), scroll to the top of this page, chapter [*Variables Explanation*](#variables-explanation). ``` We documented two options for node operators to setup WSS for `nym-node`: 1. [Using a script](#using-a-script) 2. [Step by step](#step-by-step) ### Preliminary Steps Whether you choose to setup WSS manually or using the script, the preliminary steps are mandatory to begin with before you continue with the installation. #### Firewall configuration Make sure to open all [needed ports](vps-setup.md#configure-your-firewall), adding your ``: ```sh ufw allow /tcp # for example # ufw allow 9001/tcp ``` #### Landing page configuration 1. Create server block directory for your https site: ```sh sudo mkdir -p /var/www/ ``` 2. Assign ownership using `$USER` environmental variable: ```sh sudo chown -R $USER:$USER /var/www/ ``` 3. Create a landing page in `/var/www/`. Either configure your own page (basic [syntax example](https://www.freecodecamp.org/news/introduction-to-html-basics/) or use our [template](#html-file-customization). Alternatively you can just make a simple welcome text using this command: ```sh echo "

" | sudo tee /var/www//index.html ``` 4. When done with the customization, you'll need to make sure your `nym-node` uploads the file and reference to it. This is done by opening your node configuration file located at `~/.nym/nym-nodes//config/config.toml` and changing the value of the line `landing_page_assets_path` on the `[http]` section: ```sh landing_page_assets_path = '' # for example # landing_page_assets_path = '/var/www/exit-gateway1.squad.nsl' ``` Now you are ready to set up WSS, ether using a [script](#using-a-script) or [step-by-step](#step-by-step) tutorial. ### Using a Script Using a script is a more convenient option but it takes away some customization possibilities. If you like to have your setup fully in your hands, use [*Step by step guide*](#step-by-step-guide). Before you move on, make sure you went through [*Preliminary steps*](#preliminary-steps). 1. Create a script by copying the block below and save it on your VPS as `wss_nginx_setup.sh`. ~~~admonish example collapsible=true title="Script `wss_nginx_setup.sh`" ```bash #!/bin/bash if [ "$#" -ne 2 ]; then echo "usage: sudo ./wss_nginx_setup.sh " exit 1 fi host_name=$1 port_value=$2 # preliminary checks config_file_path="${HOME}/.nym/nym-nodes/*/config/config.toml" # check if the configuration file exists if [ ! -f $config_file_path ]; then echo "configuration file not found at $config_file_path" exit 1 fi # extract hostname and wss port hostname=$(grep "hostname" $config_file_path | awk -F" = " '{print $2}' | tr -d "'") wss_port=$(grep "announce_wss_port" $config_file_path | awk -F" = " '{print $2}' | tr -d ' ') # check if hostname is empty if [ -z "$hostname" ]; then echo "hostname is empty, updating it to ${host_name}" sed -i "s|hostname = ''|hostname = '${host_name}'|" $config_file_path else echo "current hostname: $hostname" fi # check if wss port is set to 0 and update it if [ "$wss_port" -eq 0 ]; then echo "wss port is 0, updating it to ${port_value}" sed -i "s/announce_wss_port *= *0/announce_wss_port = ${port_value}/" $config_file_path else echo "current wss port: $wss_port" fi # install nginx apt update apt install -y nginx # install certbot and the nginx plugin apt install -y certbot python3-certbot-nginx # enable nginx service systemctl enable nginx.service # create a consolidated nginx configuration file nginx_config_file="/etc/nginx/sites-available/${host_name}" cat < $nginx_config_file # Reversed proxy configuration for landing page server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name ${host_name}; ssl_certificate /etc/letsencrypt/live/${host_name}/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/${host_name}/privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header X-Real-IP \$remote_addr; proxy_set_header Host \$host; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; } } # http configuration server { listen 80; listen [::]:80; server_name ${host_name} www.${host_name}; return 301 https://${host_name}\$request_uri; } # WSS configuration server { listen ${port_value} ssl http2; listen [::]:${port_value} ssl http2; server_name ${host_name}; ssl_certificate /etc/letsencrypt/live/${host_name}/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/${host_name}/privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, HEAD'; add_header 'Access-Control-Allow-Headers' '*'; proxy_http_version 1.1; proxy_set_header Upgrade \$http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Forwarded-For \$remote_addr; proxy_pass http://localhost:9000; proxy_intercept_errors on; # Enable intercepting errors from the proxy } } EOF # create a symbolic link in sites-enabled ln -s /etc/nginx/sites-available/${host_name} /etc/nginx/sites-enabled/ # test nginx configuration if ! nginx -t; then echo "nginx configuration test failed" exit 1 fi # reload nginx service systemctl reload nginx.service # obtain ssl certificates using certbot if ! certbot --nginx -d ${host_name} --non-interactive --agree-tos -m your-email@example.com; then echo "certbot failed to obtain certificates" exit 1 fi # test nginx configuration again if ! nginx -t; then echo "nginx configuration test failed after obtaining ssl certificates" exit 1 fi # reload nginx service to apply the new configuration systemctl reload nginx.service echo "script completed successfully!" echo "have a nice day!" exit 0 ``` ~~~ 2. Make the script executable: ```sh chmod u+x wss_nginx_setup.sh ``` 3. Run the script as root (with `sudo` or from the root shell): ```sh ./wss_nginx_setup.sh # hostname is your domain # wss default port is 9001 ``` 4. Restart your `nym-node` or if you're running your `nym-node` as a [`systemd` service](configuration.md#systemd), restart your service: ```sh systemctl daemon-reload service nym-node restart ``` Your `nym-node` should be configured to run over WSS now. Test it using the steps in the chapter [below](#test-wss-setup) ### Step by Step Guide Step by step guide is more advanced than using a [script](#using-a-script), but it allows for more customisation. Before you move on, make sure you finished [*Preliminary steps*](#preliminary-steps*). #### Nginx Configuration 1. Install `nginx`: ```sh apt install nginx ``` 2. Setup firewall with `ufw`. `ufw` has three profile pre-configured for `nginx`, we will need the first one for `nym-node`: - `Nginx Full`: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic) - `Nginx HTTP`: This profile opens only port 80 (normal, unencrypted web traffic) - `Nginx HTTPS`: This profile opens only port 443 (TLS/SSL encrypted traffic) ```sh ufw allow 'Nginx Full' # you can verify by ufw status ``` #### WSS & Landing page configuration We made the landing page customization directory in [*Preliminary steps*](#preliminary-steps), next steps will configure that with Nginx. 3. Configure your site to work with `nginx`. Open a new text file `/etc/nginx/sites-available/` and paste the block below. Don't forget to insert your correct values. ~~~admonish example collapsible=true title="Site configuration `/etc/nginx/sites-available/`" ```bash ##################################################### # EXCHANGE ALL & VARIABLES ! # #################################################### # Reversed proxy configuration for landing page server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name ; ssl_certificate /etc/letsencrypt/live//fullchain.pem; ssl_certificate_key /etc/letsencrypt/live//privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } # http configuration server { listen 80; listen [::]:80; if ($host = ) { return 301 https://$host$request_uri; } server_name www.; return 301 https://$request_uri; } # WSS configuration server { listen ssl http2; listen [::]: ssl http2; server_name ; ssl_certificate /etc/letsencrypt/live//fullchain.pem; ssl_certificate_key /etc/letsencrypt/live//privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, HEAD'; add_header 'Access-Control-Allow-Headers' '*'; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://localhost:9000; proxy_intercept_errors on; # Enable intercepting errors from the proxy } } ``` ~~~ 4. Activate the configuration by creating a simlink to `/etc/nginx/sites-enabled`: ```sh ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled ``` 5. Test your configuration syntax: ```sh nginx -t ``` 6. Restart `nginx`: ```sh systemctl daemon-reload && systemctl restart nginx ``` #### SSL Setup using certbot 7. Get an `SSL` certificate using certbot: ```sh apt install certbot python3-certbot-nginx certbot renew --dry-run certbot --nginx -d ``` 8. Restart your `nym-node` or if you're running your `nym-node` as a [`systemd` service](configuration.md#systemd), restart your service: ```sh systemctl daemon-reload service nym-node restart ``` Your `nym-node` should be configured to run over WSS now. Test it using the steps in the chapter [below](#test-wss-setup). ### Test WSS Setup You can do a few quick checks to test that your installation worked out and your `nym-node` is running correctly using WSS: - Check out connection with `wscat` from another (local) machine: ```sh # install sudo apt install node-ws # run wscat -c ws://: ``` - Browse your `` as URL and see your landing page. - Check Swagger API of your node using the hostname: `https:///api/v1/swagger/#/`