Configure Tor to forward hidden service traffic to Apache on localhost. Edit /etc/tor/torrc:
# /etc/tor/torrc
HiddenServiceDir /var/lib/tor/apache_onion/
HiddenServicePort 80 127.0.0.1:8080
HiddenServiceVersion 3Then configure Apache to listen exclusively on the loopback interface by editing /etc/apache2/ports.conf:
# /etc/apache2/ports.conf
Listen 127.0.0.1:8080This ensures Apache only accepts connections from the local Tor process. Remove any Listen 80 or Listen 443 directives that would expose Apache on public interfaces. Restart both services with systemctl restart tor apache2.