# Setting up a new signal server from scratch

These steps have only been successfully test on a server running Ubuntu 16.04.

In summary, the steps are as follows:
1. Install nginx
2. Install the latest LTS version of nodejs.
3. Install redis.
4. Increase ulimits.
5. Install pm2


### nginx

Install nginx:

    sudo apt-get install nginx

Then update the nginx.conf

    sudo nano /etc/nginx/sites-available/default

Verify the nginx conf works:

    sudo nginx -t

It should echo the following:

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful


### Install nodejs

    cd ~
    curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
    sudo bash nodesource_setup.sh
    sudo apt-get -y install nodejs

### Redis

    sudo apt-get install redis-server


### Limits

Edit `/etc/nginx/nginx.conf` and add the following line above the `events` section:

```
worker_rlimit_nofile 30000; # <--- Add or change this line

events {
    ...
```

Also set the following in the `events` section of the same file, `/etc/nginx/nginx.conf`:

```
events {
	worker_connections 8192; # <--- Add or change this line
	# multi_accept on;
}
```

Edit `/etc/security/limits.conf` and add the following (note: there is a tab between each column) at the bottom of the file:

```
nginx		soft	nofile		10000
nginx		hard	nofile		30000
```

Edit `/etc/sysctl.conf` and add the following line at the bottom of the file:

```
fs.file-max = 70000
```

Update the processes:

```
sysctl -p
```

Finally, restart nginx:

```
sudo systemctl restart nginx
```

## Other Settings

### Firewall

Use an AWS security group.  


### Reinstall SSL certs:

Use an AWS ELB with a certificate.

## PERFORMANCE TWEAKS

TBD:

https://blog.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/