Skip to content

Commit bf77ce5

Browse files
committed
Updates to Caddy version in HTTPS reverse proxy example
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 0724b0e commit bf77ce5

File tree

1 file changed

+25
-73
lines changed

1 file changed

+25
-73
lines changed

docs/tutorial/caddy-http-tunnel.md

Lines changed: 25 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -39,64 +39,25 @@ Setup a DNS A record for the site you want to expose using the public IP of the
3939

4040
## Run a local server to share files
4141

42-
Do not run this command in your home folder.
42+
Do not run this command in your home folder, as it will expose your entire home directory.
43+
44+
Instead, create a temporary directory and serve that instead:
4345

4446
```bash
4547
mkdir -p /tmp/shared/
4648
cd /tmp/shared/
4749

4850
echo "Hello world" > WELCOME.txt
4951

50-
# If using Python 2.x
51-
python -m SimpleHTTPServer
52-
53-
# Python 3.x
54-
python3 -m http.server
55-
```
56-
57-
This will listen on port `8000` by default.
58-
59-
## Setup Caddy 1.x
60-
61-
* Download the latest Caddy 1.x binary from the [Releases page](https://github.com/caddyserver/caddy/releases)
62-
63-
Pick your operating system, for instance Darwin for MacOS, or Linux.
64-
65-
Download the binary, extract it and install it to `/usr/local/bin`:
66-
67-
```bash
68-
mkdir -p /tmp/caddy
69-
curl -sLSf https://github.com/caddyserver/caddy/releases/download/v1.0.4/caddy_v1.0.4_darwin_amd64.zip > caddy.tar.gz
70-
tar -xvf caddy.tar.gz --strip-components=0 -C /tmp/caddy
71-
72-
sudo cp /tmp/caddy/caddy /usr/local/bin/
73-
```
74-
75-
* Create a Caddyfile
76-
77-
The `Caddyfile` configures which websites Caddy will expose, and which sites need a TLS certificate.
78-
79-
Replace `service.example.com` with your own domain.
80-
81-
Next, edit `proxy / 127.0.0.1:8000` and change the port `8000` to the port of your local webserver, for instance `3000` or `8080`. For our example, keep it as `8000`.
82-
83-
```sh
84-
service.example.com
85-
86-
proxy / 127.0.0.1:8000 {
87-
transparent
88-
}
52+
inlets-pro fileserver --webroot ./ \
53+
--allow-browsing
8954
```
9055

91-
Start the Caddy binary, it will listen on port 80 and 443.
92-
93-
```
94-
sudo ./caddy
95-
```
56+
The command listens on port `8080` by default, but you can change is as desired with `--port`
9657

97-
If you have more than one website, you can add them to the Caddyfile on new lines.
58+
The `--allow-browsing` flag allows directory listing and traversal through the browser.
9859

99-
> You'll need to run caddy as `sudo` so that it can bind to ports 80, and 443 which require additional privileges.
60+
If you're sharing files with a colleague or friend, you can add `--allow-browsing=false` and share the exact URL with them instead.
10061

10162
## Start the inlets-pro client on your local side
10263

@@ -123,29 +84,9 @@ inlets-pro tcp client \
12384

12485
Note that `--upstream localhost` will connect to Caddy running on your computer, if you are running Caddy on another machine, use its IP address here.
12586

126-
## Check it all worked
127-
128-
You'll see that Caddy can now obtain a TLS certificate.
129-
130-
Go ahead and visit: `https://service.example.com`
131-
132-
Congratulations, you've now served a TLS certificate directly from your laptop. You can close caddy and open it again at a later date. Caddy will re-use the certificate it already obtained and it will be valid for 3 months. To renew, just keep Caddy running or open it again whenever you need it.
133-
13487
## Setup Caddy 2.x
13588

136-
For Caddy 2.x, the Caddyfile format changes.
137-
138-
Let's say you're running a Node.js service on port 3000, and want to expose it with TLS on the domain "service.example.com":
139-
140-
```
141-
git clone https://github.com/alexellis/expressjs-k8s/
142-
cd expressjs-k8s
143-
144-
npm install
145-
http_port=3000 npm start
146-
```
147-
148-
The local site will be served at http://127.0.0.1:3000
89+
Here's an example Caddyfile that will reverse-proxy to the local file-server using the domain name `service.example.com`:
14990

15091
```Caddyfile
15192
{
@@ -154,22 +95,26 @@ The local site will be served at http://127.0.0.1:3000
15495
15596
service.example.com
15697
157-
reverse_proxy 127.0.0.1:3000 {
98+
reverse_proxy 127.0.0.1:8080 {
15899
}
159100
```
160101

161102
Note the `acme_ca` being used will receive a staging certificate, remove it to obtain a production TLS certificate.
162103

163-
Now [download Caddy 2.x](https://caddyserver.com/download) for your operating system.
104+
Now [download Caddy 2.x](https://caddyserver.com/download) for your operating system. You can get it from the downloads page, or if you're a Linux user on an amd64 or arm64 machine, you can use arkade to do everything required via `arkade system install caddy`. See `arkade system install --help` for more options.
105+
106+
Once you have the binary, you can run it with the following command:
164107

165108
```bash
166109
sudo ./caddy run \
167110
-config ./Caddyfile
168111
```
169112

170-
`sudo` - is required to bind to port 80 and 443, although you can potentially update your OS to allow binding to low ports without root access.
113+
`sudo` - is required to bind to port 80 and 443, although you can potentially update your OS to allow binding to low ports without root access. See this [StackOverflow question for more](https://superuser.com/questions/710253/allow-non-root-process-to-bind-to-port-80-and-443).
171114

172-
You should now be able to access the Node.js website via the `https://service.example.com` URL.
115+
You should now be able to access the fileserver via the `https://service.example.com` URL.
116+
117+
If you wanted to expose something else like Grafana, you could simply edit your Caddyfile's `reverse_proxy` line, then restart Caddy.
173118

174119
Caddy also supports multiple domains within the same file, so that you can expose multiple internal or private websites through the same tunnel.
175120

@@ -187,5 +132,12 @@ openfaas.example.com {
187132
}
188133
```
189134

190-
If you have services running on other machines you can change `127.0.0.1:8080` to a different IP address such as that of your Raspberry Pi if you had something like [OpenFaaS](https://github.com/openfaas/) running there.
135+
If you have services running on other machines you can change `127.0.0.1:8080` to a different IP address such as that of your Raspberry Pi if you had something like [OpenFaaS CE](https://github.com/openfaas/faas) or [faasd CE](https://github.com/openfaas/faasd) running there.
136+
137+
## Check it all worked
191138

139+
You'll see that Caddy can now obtain a TLS certificate.
140+
141+
Go ahead and visit: `https://service.example.com`
142+
143+
Congratulations, you've now served a TLS certificate directly from your laptop. You can close caddy and open it again at a later date. Caddy will re-use the certificate it already obtained and it will be valid for 3 months. To renew, just keep Caddy running or open it again whenever you need it.

0 commit comments

Comments
 (0)