@@ -30,3 +30,111 @@ The server can then be started in production mode using:
3030``` bash
3131NODE_ENV=production npm start
3232```
33+
34+ ## Configuring Server
35+
36+ For best compatibility with this guide, ensure the server is running
37+ Ubuntu 16.04 LTS. It should be fairly trivial to port to newer versions.
38+
39+ ### Installing VPN
40+ In order to ensure bi-directional communication between the Robot and
41+ RobotSlam server they need to be on the same local network. This is
42+ easily achieved by setting up a OpenVPN instance.
43+
44+ Installing and configuring OpenVPN is easily achived using
45+ https://github.com/Nyr/openvpn-install .
46+
47+ ``` bash
48+ wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
49+ ```
50+
51+ * Remember to ensure the port is open in Security Groups.*
52+
53+ ### Installing nginx as reverse proxy
54+
55+ ``` bash
56+ sudo npm install nginx
57+ ```
58+
59+ #### Installing SSL certificate from Lets Encrypt
60+
61+ Follow the instructions at https://certbot.eff.org/#ubuntuxenial-nginx
62+
63+ ``` bash
64+ sudo add-apt-repository ppa:certbot/certbot
65+ sudo apt-get update
66+ sudo apt-get install certbot
67+ ```
68+
69+ #### Adding configuration to nginx
70+
71+ Create the file ` /etc/nginx/sites-available/robotslam ` with the following content.
72+ ```
73+ server {
74+ listen 80;
75+ server_name robotslam.thinxmate.com;
76+
77+ location / {
78+ return 301 https://$server_name$request_uri;
79+ }
80+ }
81+
82+ server {
83+ listen 443 ssl;
84+ server_name robot.thinxmate.com;
85+
86+ client_max_body_size 10G;
87+
88+ location / {
89+ # Basic authentication
90+ auth_basic "Restricted Content";
91+ auth_basic_user_file /etc/nginx/.htpasswd;
92+
93+ proxy_pass http://localhost:3000;
94+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
95+ proxy_set_header Host $http_host;
96+ proxy_set_header X-Forwarded-Proto $scheme;
97+ proxy_buffering off;
98+ }
99+
100+ ssl on;
101+ ssl_certificate /etc/letsencrypt/live/robotslam.thinxmate.com/fullchain.pem;
102+ ssl_certificate_key /etc/letsencrypt/live/robotslam.thinxmate.com/privkey.pem;
103+ ssl_prefer_server_ciphers On;
104+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
105+ ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
106+ }
107+ ```
108+
109+ Enable the new site using ` sudo ln -s /etc/nginx/sites-available/robotslam /etc/nginx/sites-enabled/ `
110+ and restart nginx ` sudo systemctl restart nginx ` .
111+
112+ ### Installing NVM
113+ In order to ensure we install the correct Node version, we use the
114+ Node Version Manager, https://github.com/creationix/nvm .
115+
116+ ``` bash
117+ nvm install 7.*
118+ nvm alias default 7.*
119+ ```
120+
121+ ### Configuring Systemd (Node.js)
122+
123+ Create the file ` /lib/systemd/system/robotslam.service ` with the following content:
124+
125+ ``` systemd
126+ [Unit]
127+ Description=Robotslam Node.js application
128+ After=network.target
129+
130+ [Service]
131+ Environment=NODE_ENV=production
132+ Type=simple
133+ User=ubuntu
134+ WorkingDirectory=/home/ubuntu/app
135+ ExecStart=/home/ubuntu/app/start.sh
136+ Restart=on-failure
137+
138+ [Install]
139+ WantedBy=multi-user.target
140+ ```
0 commit comments