Nginx config to redirect for rickroll

scroll down to new question

I assume that using the trashcan icon next to that entry did not work? If so, edit file /etc/dnsmasq.d/05-pihole-custom-cname.conf and delete it there.

We will need more information on what you are trying to do. Start with posting the current contents of the file listed above.

cname=google.com,youtube.com/watch?v=dQw4w9WgXcQ

Gives google.com’s server IP address could not be found.

This is not a valid domain name.

I know, but how can I make it redirect to a domain with a url path?

Or must I just setup a simple webserver which redirects and it's not possible with DNS?

You cannot with a DNS server that works at the domain level. You need a proxy server.

oh k thanks

okay say I have setup a proxy server on rickroll.local, which redirects to youtube (and it works, I tested it)
cname config

so like this would redirect pornhub.com to rickroll.local to youtube right?

Try it. There's a limitation in the Target Domain that's not documented. The Target Domain needs to be a domain that Pi-hole is already managing. The test to see if it will work is to dig the CNAME and see if there is an actual IP address returned, or just a CNAME record without the additional IP address. The latter will not work.

I get

pornhub.com refused to connect.

Do a dig pornhub.com @<pi-hole IP> and post the response.

;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5677
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;pornhub.com.                   IN      A

;; ANSWER SECTION:
pornhub.com.            2       IN      CNAME   rickroll.local.
rickroll.local.         2       IN      A       192.168.2.200

;; Query time: 253 msec
;; SERVER: 192.168.2.200#53(192.168.2.200)
;; WHEN: Tue Dec 08 19:18:38 CET 2020
;; MSG SIZE  rcvd: 84

That's all the information that Pi-hole can provide. I think the issue then is on the proxy.

Try using curl -IL http://pornhub.com and see what headers are reported and if the problem is at the proxy.

Note, https://pornhub.com likely will not work as TLS prevents most attempts to impersonate sites.

https://pornhub.com gives connection refused

http://pornhub.com gives

HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.2
Date: Tue, 08 Dec 2020 18:22:15 GMT
Content-Type: text/html
Content-Length: 185
Location: http://pornhub.com/admin/
Connection: keep-alive

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 08 Dec 2020 18:22:15 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Set-Cookie: PHPSESSID=ul9gjqm7d8g9l03llkfj7h31g0; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache

Your nginx proxy is not configured correctly.

How would I configure correctly?

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

        server_name rickroll.local;
        rewrite ^/$ http://youtube.com/watch?v=dQw4w9WgXcQ permanent;
}

That's not something we can advise on. It looks like it's redirecting to http://pornhub.com/admin/ and not rickroll.local.

I guess that's pi-hole redirecting it to /admin is it?

Pi-hole uses lighttpd.

I set it up to use nginx

https://docs.pi-hole.net/guides/nginx-configuration/