|
13 | 13 | # Table of Contents |
14 | 14 |
|
15 | 15 | - [Configurations](#configurations) - System and Service Setup |
| 16 | + - [Cloudflare Tunnel Setup]() - Setup Cloudflare Tunnel |
16 | 17 | - [EC2 Web Server](#ec2-user-data-to-add-web-server-with-web-page-on-80-port-number) - Deploy Apache + custom landing page via user-data |
17 | 18 | - [Docker Remote API](#enable-docker-remote-api) - Configure Docker daemon for remote management on port 2375 |
18 | 19 | - [VIM Settings](#configuring-vim-according-to-our-needs) - Productivity-focused VIM configuration (line numbers, indentation, colors) |
|
80 | 81 | # Configurations |
81 | 82 |
|
82 | 83 |
|
| 84 | +### Cloudflare Tunnel Setup |
| 85 | +Assumption |
| 86 | +- Name of the machine : fzryzen |
| 87 | +- Domain we currently own : afzalex.com |
| 88 | +- Domain we want to tunnel : fzryzen.afzalex.com |
| 89 | + |
| 90 | +Let's set the variables to use in following code snippets |
| 91 | +```bash |
| 92 | +export CF_TUNNEL_NAME=fzryzen |
| 93 | +export CF_TARGET_DOMAIN=fzryzen.afzalex.com |
| 94 | +``` |
| 95 | + |
| 96 | + |
| 97 | +Prerequisites |
| 98 | +- `afzalex.com` or any other domain is added to Cloudflare |
| 99 | +- Nameservers are pointing to Cloudflare |
| 100 | + |
| 101 | +Install Cloudflared in Server |
| 102 | +```bash |
| 103 | +curl -fsSL https://cloudflare.com/install.sh | sudo bash |
| 104 | +cloudflared --version |
| 105 | +``` |
| 106 | + |
| 107 | +Login to Cloudflared from server |
| 108 | +```bash |
| 109 | +cloudflared tunnel login |
| 110 | +``` |
| 111 | +- A browser page opens |
| 112 | +- Login to Cloudflare |
| 113 | +- Select `afzalex.com` or any other domain |
| 114 | +- Approve |
| 115 | +- This creates credentials in `~/.cloudflared/` |
| 116 | + |
| 117 | +Create tunnel named `fzryzen` and create dns record automatically. |
| 118 | +*In this example trying to route `fzryzen.afzalex.com` to `fzryzen` machine* |
| 119 | +```bash |
| 120 | +cloudflared tunnel create "${CF_TUNNEL_NAME}" |
| 121 | +cloudflared tunnel route dns "${CF_TUNNEL_NAME}" "${CF_TARGET_DOMAIN}" |
| 122 | +``` |
| 123 | + |
| 124 | +Create the Cloudflared config file |
| 125 | +```bash |
| 126 | +export TUNNEL_ID=$(basename ~/.cloudflared/*.json .json) |
| 127 | +cat <<EOF | envsubst | tee /tmp/cloudflared-config.yml |
| 128 | +tunnel: ${TUNNEL_ID} |
| 129 | +credentials-file: /root/.cloudflared/${TUNNEL_ID}.json |
| 130 | +
|
| 131 | +ingress: |
| 132 | + - hostname: $CF_TARGET_DOMAIN |
| 133 | + service: http://localhost:80 |
| 134 | +
|
| 135 | + - service: http_status:404 |
| 136 | +EOF |
| 137 | +``` |
| 138 | + |
| 139 | +Copy this config into /etc/cloudflared directory and then install cloudflared service |
| 140 | +```bash |
| 141 | +sudo mkdir -p /etc/cloudflared |
| 142 | +sudo cp /tmp/cloudflared-config.yml /etc/cloudflared/config.yml |
| 143 | +sudo cloudflared service install |
| 144 | +sudo systemctl enable cloudflared |
| 145 | +sudo systemctl start cloudflared |
| 146 | +``` |
| 147 | + |
| 148 | + |
| 149 | + |
83 | 150 | ### EC2 user-data to add web server with web page on 80 port number |
84 | 151 | ```bash |
85 | 152 | #!/usr/bin/env bash |
|
0 commit comments