Change Pihole Port to 8080 (NGINX)

I have installed the LEMP stack and then Pihole using dietpi-software. I would like to change the default port for Pihole to something like http://ip:8080/admin instead of http://ip/admin.

I have tried adding the ‘listen’ directive in the /etc/nginx/sites-dietpi/dietpi-pihole.conf file, but I couldn’t restart nginx, and the nginx test fails.

# Based on:

# Admin panel
location ~ ^(?:/html|)/admin(?:$|/) {
listen: 8080;
        # Block public access to admin page, if enabled
        # - To enable: cd /etc/nginx/sites-dietpi; mv dietpi-pihole-block_public_admin.on
        # - To disable: cd /etc/nginx/sites-dietpi; mv dietpi-pihole-block_public_admin.on
        include sites-dietpi/dietpi-pihole-block_public_admin.*on;

        # Block . files from being served, such as .git, .github, .gitignore
        location ~ ^(?:/html|)/admin/\. { return 404; }

        # Add response headers
        add_header X-Pi-hole "The Pi-hole Web interface is working!";
        add_header X-Content-Type-Options "nosniff";
        set $frame_options "deny";
        add_header X-Frame-Options "$frame_options";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag "noindex, nofollow";
        add_header X-Permitted-Cross-Domain-Policies "none";
        add_header Referrer-Policy "same-origin";
        add_header Content-Security-Policy "default-src 'self' 'unsafe-inline'";

This is the wrong configuration file. PiHole is not an own app. It’s a web site and you would need to change whole Nginx configuration to LISTEN to port 8080

nano /etc/nginx/sites-available/default
1 Like

Thank you for your prompt response. Would it be possible to add a specific port (8080) only to Pi-hole?

This is not possible, the whole webserver will then listen on that port, not only the pihole dashboard. You could set up one webserver just for pihole, which listens only on port 8080. And then start another one on port 80. But It would be a waste of system resources IMO.
Why do you want the dashboard on another port?

partially correct. It would require some manual configuration steps, but it should be possible. OP would need to use Nginx Server Blocks (Virtual Hosts) to have different configuration for different domains. Following gives an idea on how it could look like How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 16.04 | DigitalOcean

1 Like