Skip to content

Commit a51f062

Browse files
committed
Update deployment docs
1 parent 32579b9 commit a51f062

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

deployment.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
# Deployment
22

3-
Deploying this service is a short two step process. This assumes you already have a server with an OS of your choice that runs Node setup, if not refer to the [acquiring a server](#acquiring-a-server) section.
3+
Deploying this service is a short three step process. This assumes you already have a server with an OS of your choice that runs Node setup, if not refer to the [acquire a server](#acquire-a-server) section.
44

5-
1. Upload the files of the service to your server and start the service
6-
2. Setup `nginx` as a reverse proxy to make your service publicy accessible
5+
1. Upload the files of the service to your server (you should be able to do this on your own)
6+
2. Start and daemonize the app with `pm2`
7+
3. Setup `nginx` as a reverse proxy to make your service publicy accessible
78

8-
This is what my `nginx` conf looks like in `/etc/nginx/sites-available/default`:
9+
## Start and deamonize the app
10+
11+
Once all the files for this microservice are uploaded we'll use `pm2` to start and deamonize the app. This means that the app isn't bound to the terminal, and we'll also make `pm2` start the app when the server start.
12+
13+
First run `npm install -g pm2` to get `pm2`, then run `pm2 start npm -- start`. This tells `pm2` to run `npm start` in the background.
14+
15+
To make sure our service stays up even if the server reboots we run `pm2 startup ubuntu` (replace `ubuntu` with whatever OS you're using) and `pm2 save`.
16+
17+
## Set up `nginx`
18+
19+
Get `nginx` by running `sudo apt-get install nginx`, then configure it to reroute all incoming requests to the server to our server.
20+
21+
Delete the default site from nginx by running `sudo rm /etc/nginx/sites-enabled/default`, then create a new one by running `sudo touch /etc/nginx/sites-enabled/<yoursite>`. (replace `<yoursite>` with your site name)
22+
23+
We want to reroute all requests for any path that come in to our service, so edit the `/etc/nginx/sites-enabled/<yoursite>` file to look like this:
924

1025
```nginx
1126
server {
12-
listen 80;
13-
server_name yourserver.com;
14-
15-
location ~^.*$ {
16-
proxy_set_header X-Real-IP $remote_addr;
17-
proxy_set_header X-Forwarded-For $remote_addr;
18-
proxy_set_header Host $host;
19-
proxy_pass http://localhost:3000;
20-
}
27+
listen 80;
28+
server_name yoursite.com;
29+
30+
location ~^.*$ {
31+
proxy_set_header X-Real-IP $remote_addr;
32+
proxy_set_header X-Forwarded-For $remote_addr;
33+
proxy_set_header Host $host;
34+
proxy_pass http://localhost:3000;
35+
}
2136
}
2237
```
2338

2439
(note that I have no idea what I'm doing here, this was copied from [this tutorial](https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-for-apache))
2540

26-
## Acquiring a server
41+
## Acquire a server
2742

2843
If you don't have a server to deploy this on just yet, here is what I do:
2944

0 commit comments

Comments
 (0)