Cloudflare Tunnel with NGINX web server on a Raspberry Pi 4

I have a Raspberry Pi 4 running an NGINX web server which I wanted to expose publicly via my own custom domain purchased from GoDaddy. I setup my custom domain using Cloudflare’s nameservers.

I decided to use Cloudflare Tunnels to access my web server via my own custom domain. However, I get an error, when I try to add a public hostname to port 80. (I am not bothered with https on port 443 for now.)

I am not sure what I am doing wrong. I was able to add other public hostnames with subdomains, like plex.mydomain.com but I want my NGINX web server to point to www.mydomain.com.

Can anyone point me in the right direction?

The error is quite clear. You already have that hostname allocated in DNS. You can’t have a tunnel and a DNS record for the same hostname. Delete the DNS record, and your tunnel should automatically fill that slot.

I thought of deleting the DNS record but I would need to delete both the A and CNAME records right?

I’m worried that deleting the A record would cause some other issues.

Is it safe to delete both the A and CNAME records?

You’d only need to delete the hostname you’re adding to the tunnel. The ‘www’ CNAME will follow whatever path you set for the apex domain.

Will try this and see if everything works.

@sdayman That seemed to work, I think. Thanks.

I still do have one small issue though. I am hosting 2 websites on my Raspberry Pi 4. I have 2 domains, mydomain.com and mydomain2.com, and the NGINX web server configuration handles which sites to serve.

I’ve set up the tunnel, the DNS records for mydomain.com and mydomain2.com like so:

The NGINX configuration for mydomain.com:

server {
    listen 80;
    listen [::]:80;

    root /var/www/html/mydomain.com;
    index index.html index.htm;
    server_name mydomain.com www.mydomain.com;

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

The NGINX configuration for mydomain2.com:

server {
    listen 80;
    listen [::]:80;

    root /var/www/html/mydomain2.com;
    index index.html index.htm;
    server_name mydomain2.com www.mydomain2.com;

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

I have done the following tests:

http://mydomain.com - works
https://mydomain.com - works
http://www.mydomain.com - redirects to https://www.mydomain.com
https://www.mydomain.com - doesn't work
http://home-assistant.mydomain.com - works
https://home-assistant.mydomain.com - works
http://plex.mydomain.com - works
https://plex.mydomain.com - works
http://mydomain2.com - works
https://mydomain2.com - works
http://www.mydomain2.com - works
https://www.mydomain2.com - works

Any ideas what is wrong with:

http://www.mydomain.com - redirects to https://www.mydomain.com
https://www.mydomain.com - doesn't work

I get the error www.mydomain.com redirected you too many times.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.