3
3
## Requirements
4
4
5
5
1 . You'll need a subdomain and the a wildcard subdomain configured that resolves to server.
6
+
6
7
2 . Install ** nginx** (assuming you're on Debian/Ubuntu):
7
8
8
9
``` console
12
13
3. Stop NGINX:
13
14
14
15
```console
15
- sudo service stop nginx
16
- ```
16
+ sudo service stop nginx
17
+ ```
17
18
18
19
## Adding Coder deployment subdomain
19
20
20
21
> This example assumes Coder is running locally on ` 127.0.0.1:3000` for the subdomain ` YOUR_SUBDOMAIN` e.g. ` coder.example.com` .
21
22
22
- - Create NGINX configuration for this app: `sudo touch /etc/nginx/sites-available/YOUR_SUBDOMAIN`
23
+ 1. Create NGINX configuration for this app:
24
+
25
+ ```console
26
+ sudo touch /etc/nginx/sites-available/YOUR_SUBDOMAIN
27
+ ```
28
+
29
+ 2. Activate this file :
23
30
24
- - Activate this file : `sudo ln -s /etc/nginx/sites-available/YOUR_SUBDOMAIN /etc/nginx/sites-enabled/YOUR_SUBDOMAIN`
31
+ ```console
32
+ sudo ln -s /etc/nginx/sites-available/YOUR_SUBDOMAIN /etc/nginx/sites-enabled/YOUR_SUBDOMAIN
33
+ ```
25
34
26
35
## Install and configure LetsEncrypt Certbot
27
36
28
- Install LetsEncrypt Certbot: Refer to the [CertBot documentation](https://certbot.eff.org/instructions?ws=other&os=pip&tab=wildcard)
37
+ 1. Install LetsEncrypt Certbot: Refer to the [CertBot documentation](https://certbot.eff.org/instructions?ws=other&os=pip&tab=wildcard)
29
38
30
39
## Create DNS provider credentials
31
40
32
- - 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:
41
+ 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
+ - Zone - DNS - Edit
33
43
34
- - Zone - DNS - Edit
44
+ 2. Create a file in `.secrets/certbot/cloudflare.ini` with the following content :
35
45
36
- - Create a file in `.secrets/certbot/cloudflare.ini` with the following content :
37
- - `dns_cloudflare_api_token = YOUR_API_TOKEN`
46
+ - `dns_cloudflare_api_token = YOUR_API_TOKEN`
38
47
39
48
## Create the certificate
40
49
41
- - Create the wildcard certificate:
50
+ 1. Create the wildcard certificate:
42
51
43
- ```console
44
- sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini -d coder.example.com *.coder.example.com
45
- ```
52
+ ```console
53
+ sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini -d coder.example.com *.coder.example.com
54
+ ```
46
55
47
56
## Configure nginx
48
57
49
- Edit the file with : ` sudo nano /etc/nginx/sites-available/YOUR_SUBDOMAIN ` and add the following content :
50
-
51
- ``` nginx
52
- server {
53
- server_name YOUR_SUBDOMAIN;
54
-
55
- # HTTP configuration
56
- listen 80;
57
- listen [::]:80;
58
-
59
- # HTTP to HTTPS
60
- if ($scheme != "https") {
61
- return 301 https://$host$request_uri;
62
- } # managed by Certbot
63
-
64
- # HTTPS configuration
65
- listen [::]:443 ssl ipv6only=on; # managed by Certbot
66
- listen 443 ssl; # managed by Certbot
67
- ssl_certificate /etc/letsencrypt/live/YOUR_SUBDOMAIN/fullchain.pem;
68
- ssl_certificate_key /etc/letsencrypt/live/YOUR_SUBDOMAIN/privkey.pem;
69
- include /etc/letsencrypt/options-ssl-nginx.conf;
70
- ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
71
-
72
- location / {
73
- proxy_pass http://127.0.0.1:3000;
74
- proxy_http_version 1.1;
75
- proxy_set_header Upgrade $http_upgrade;
76
- proxy_set_header Connection $connection_upgrade;
77
- proxy_set_header Host $server_name;
78
- proxy_set_header X-Real-IP $remote_addr;
79
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
80
- proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
81
- add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
58
+ 1. Edit the file with :
59
+
60
+ ```console
61
+ sudo nano /etc/nginx/sites-available/YOUR_SUBDOMAIN
62
+ ```
63
+
64
+ 2. Add the following content :
65
+
66
+ ```nginx
67
+ server {
68
+ server_name YOUR_SUBDOMAIN;
69
+
70
+ # HTTP configuration
71
+ listen 80;
72
+ listen [::]:80;
73
+
74
+ # HTTP to HTTPS
75
+ if ($scheme != "https") {
76
+ return 301 https://$host$request_uri;
77
+ }
78
+
79
+ # HTTPS configuration
80
+ listen [::]:443 ssl ipv6only=on;
81
+ listen 443 ssl;
82
+ ssl_certificate /etc/letsencrypt/live/YOUR_SUBDOMAIN/fullchain.pem;
83
+ 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
+
87
+ location / {
88
+ proxy_pass http://127.0.0.1:3000;
89
+ proxy_http_version 1.1;
90
+ proxy_set_header Upgrade $http_upgrade;
91
+ proxy_set_header Connection $connection_upgrade;
92
+ proxy_set_header Host $server_name;
93
+ proxy_set_header X-Real-IP $remote_addr;
94
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
95
+ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
96
+ add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
97
+ }
82
98
}
83
- }
84
- ```
99
+ ```
85
100
86
101
> Don' t forget to change :
87
102
>
@@ -90,17 +105,27 @@ server {
90
105
91
106
## Refresh certificates automatically
92
107
93
- - Create a new file in ` /etc/cron.weekly ` : ` sudo touch /etc/cron.weekly/certbot `
94
- - Make it executable : ` sudo chmod +x /etc/cron.weekly/certbot `
95
- - And add this code :
108
+ 1. Create a new file in `/etc/cron.weekly` :
109
+
110
+ ```console
111
+ sudo touch /etc/cron.weekly/certbot
112
+ ```
113
+
114
+ 2. Make it executable :
115
+
116
+ ```console
117
+ sudo chmod +x /etc/cron.weekly/certbot
118
+ ```
119
+
120
+ 3. And add this code :
96
121
97
- ``` sh
98
- #! /bin/sh
99
- sudo certbot renew -q
100
- ```
122
+ ```sh
123
+ #!/bin/sh
124
+ sudo certbot renew -q
125
+ ```
101
126
102
127
## Restart NGINX
103
128
104
129
- `sudo service nginx restart`
105
130
106
- And that's it, you should now be able to access Coder via ` https://YOUR_SUBDOMAIN ` !
131
+ And that's it, you should now be able to access Coder at `https://YOUR_SUBDOMAIN`!
0 commit comments