|
2 | 2 |
|
3 | 3 | ## Requirements
|
4 | 4 |
|
5 |
| -1. You'll need a subdomain and the a wildcard subdomain configured that resolves to server. |
| 5 | +1. Start a Coder deployment with a wildcard subdomain. See [this guide](https://coder.com/docs/coder/v1.20/setup/installation#step-1-create-a-subdomain) for more information. |
| 6 | +1. You'll need a subdomain and the a wildcard subdomain configured that resolves to server's public ip. |
| 7 | + > For example, to use `coder.example.com` as your subdomain, configure `coder.example.com` and `*.coder.example.com` to point to your server's public ip. This can be done by adding A records in your DNS provider's dashboard. |
6 | 8 |
|
7 |
| -2. Install **nginx** (assuming you're on Debian/Ubuntu): |
| 9 | +2. Install NGINX (assuming you're on Debian/Ubuntu): |
8 | 10 |
|
9 | 11 | ```console
|
10 | 12 | sudo apt install nginx
|
11 | 13 | ```
|
12 | 14 |
|
13 |
| -3. Stop NGINX: |
| 15 | +3. Stop NGINX service: |
14 | 16 |
|
15 | 17 | ```console
|
16 |
| - sudo service stop nginx |
| 18 | + sudo systemctl stop nginx |
17 | 19 | ```
|
18 | 20 |
|
19 | 21 | ## Adding Coder deployment subdomain
|
|
26 | 28 | sudo touch /etc/nginx/sites-available/YOUR_SUBDOMAIN
|
27 | 29 | ```
|
28 | 30 |
|
29 |
| -2. Activate this file : |
| 31 | +2. Activate this file: |
30 | 32 |
|
31 | 33 | ```console
|
32 | 34 | sudo ln -s /etc/nginx/sites-available/YOUR_SUBDOMAIN /etc/nginx/sites-enabled/YOUR_SUBDOMAIN
|
|
41 | 43 | 1. Create an API token for the DNS provider you're using: e.g [CloudFlare](https://dash.cloudflare.com/profile/api-tokens) with the following permissions:
|
42 | 44 | - Zone - DNS - Edit
|
43 | 45 |
|
44 |
| -2. Create a file in `.secrets/certbot/cloudflare.ini` with the following content : |
| 46 | +2. Create a file in `.secrets/certbot/cloudflare.ini` with the following content: |
45 | 47 |
|
46 |
| - - `dns_cloudflare_api_token = YOUR_API_TOKEN` |
| 48 | + ```ini |
| 49 | + dns_cloudflare_api_token = YOUR_API_TOKEN |
| 50 | + ``` |
| 51 | + |
| 52 | +3. Set the correct permissions: |
| 53 | + |
| 54 | + ```console |
| 55 | + sudo chmod 600 ~/.secrets/certbot/cloudflare.ini |
| 56 | + ``` |
47 | 57 |
|
48 | 58 | ## Create the certificate
|
49 | 59 |
|
|
55 | 65 |
|
56 | 66 | ## Configure nginx
|
57 | 67 |
|
58 |
| -1. Edit the file with : |
| 68 | +1. Edit the file with: |
59 | 69 |
|
60 | 70 | ```console
|
61 | 71 | sudo nano /etc/nginx/sites-available/YOUR_SUBDOMAIN
|
62 | 72 | ```
|
63 | 73 |
|
64 |
| -2. Add the following content : |
| 74 | +2. Add the following content: |
65 | 75 |
|
66 | 76 | ```nginx
|
67 | 77 | server {
|
|
81 | 91 | listen 443 ssl;
|
82 | 92 | ssl_certificate /etc/letsencrypt/live/YOUR_SUBDOMAIN/fullchain.pem;
|
83 | 93 | ssl_certificate_key /etc/letsencrypt/live/YOUR_SUBDOMAIN/privkey.pem;
|
84 |
| - include /etc/letsencrypt/options-ssl-nginx.conf; |
85 |
| - ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; |
86 | 94 |
|
87 | 95 | location / {
|
88 | 96 | proxy_pass http://127.0.0.1:3000; # Change this to your coder deployment port default is 3000
|
89 | 97 | proxy_http_version 1.1;
|
90 | 98 | proxy_set_header Upgrade $http_upgrade;
|
91 |
| - proxy_set_header Connection $connection_upgrade; |
92 | 99 | proxy_set_header Host $host;
|
93 | 100 | proxy_set_header X-Real-IP $remote_addr;
|
94 | 101 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
98 | 105 | }
|
99 | 106 | ```
|
100 | 107 |
|
101 |
| -> Don't forget to change : |
| 108 | +> Don't forget to change: |
102 | 109 | >
|
103 | 110 | > - `YOUR_SUBDOMAIN` by your (sub)domain e.g. `coder.example.com`
|
104 | 111 |
|
105 | 112 | ## Refresh certificates automatically
|
106 | 113 |
|
107 |
| -1. Create a new file in `/etc/cron.weekly` : |
| 114 | +1. Create a new file in `/etc/cron.weekly`: |
108 | 115 |
|
109 | 116 | ```console
|
110 | 117 | sudo touch /etc/cron.weekly/certbot
|
111 | 118 | ```
|
112 | 119 |
|
113 |
| -2. Make it executable : |
| 120 | +2. Make it executable: |
114 | 121 |
|
115 | 122 | ```console
|
116 | 123 | sudo chmod +x /etc/cron.weekly/certbot
|
117 | 124 | ```
|
118 | 125 |
|
119 |
| -3. And add this code : |
| 126 | +3. And add this code: |
120 | 127 |
|
121 | 128 | ```sh
|
122 | 129 | #!/bin/sh
|
|
125 | 132 |
|
126 | 133 | ## Restart NGINX
|
127 | 134 |
|
128 |
| -- `sudo service nginx restart` |
| 135 | +- `sudo systemctl restart nginx` |
129 | 136 |
|
130 | 137 | And that's it, you should now be able to access Coder at `https://YOUR_SUBDOMAIN`!
|
0 commit comments