Configure tunnel

I just started use the tunnels but something maybe I am missing. Because I am still facing same issue. I want make clear again. I have one website and it is deployed with nginx webserver. Also, I have microservice project and that project is using nginx inside of docker container. I will add below the nginx config files and
Cloudflare.yml file.

Nginx config file of my microservice is as below.

worker_processes auto;

events {
  worker_connections 1024;
}

http {

  server {
    listen 80 default_server;
    server_name "";
    return 444;
  }

  server {
    server_name game-dev.example.com;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      proxy_pass http://game_nodes;
      proxy_redirect off;
    }
  }
  server {
    if ($host = game-dev.example.com) {
      return 301 https://$host$request_uri;
    }


    listen 80;
    listen [::]:80;
    server_name game-dev.example.com;
    return 404;
  }

  upstream game_nodes {
#    enable sticky session
 #   ip_hash;
    server game-alpha:3000;
    keepalive 8;
  }

  server {
    server_name api-dev.example.com;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://main_nodes;
      proxy_redirect off;

    }
  }

  server {
   # if ($host = api-dev.example.com) {
    #  return 301 https://$host$request_uri;
    #}

    listen 80;
    listen [::]:80;
    server_name api-dev.example.com;
    return 404;
  }

  upstream main_nodes {
    server main-alpha:8000;
    server main-beta:8000;
    keepalive 8;
  }
}

Nginx config fle of the website is as below

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name  example.com www.example.com;
    root /var/www/example.com;
    index index.html;

    ssl_certificate /etc/ssl/certs/example.com.pem;
    ssl_certificate_key /etc/ssl/private/example.com.key;
    ssl_client_certificate /etc/ssl/certs/origin-pull-ca.pem;
    ssl_verify_client on;

    client_max_body_size 100M;
  
    autoindex off;

    location / {
        try_files $uri $uri/ =404;

    }

}

Also config.yml file of the Cloudflare is as below

tunnel: <UUID>
credentials-file: /home/cihat/.cloudflared/<UUID>.json

ingress:
  - hostname: example.com
    service: http://localhost:80  
  - service: http_status:404

Finally, the ERROR:

for nginx Cannot start service nginx: driver failed programming external connectivity on endpoint nginx (9b1ec95f7ad7a643bd4a3b12715a49e817cedd9110c069ffa42dd107508751df): Error starting userland proxy: listen tcp4 0.0.0.0:443: bind: address already in use

May I know what I am missing ?

Tunnels would allow you to have multiple websites on a single host whilst still being able to use the standard ports (80 and 443) on the public hostnames.

However, like sandro mentioned, you do first need to get the services running locally on different ports before you can configure cloudflared to map hostnames to them.

cloudflare --> cloudflared ┌────► www.example.org ───────► localhost:80
                           │
                           ├────► waffles.example.org ───► localhost:81
                           │
                           └────► blog.example.org ──────► localhost:82
1 Like