Captive Portal on Raspberry Pi (hostapd, dnsmasq, Nginx): No Wi-Fi login popup on Android & HTTPS failing
06:43 03 Oct 2026

Although I used an AI tool to help organize my thoughts for this response, the content reflects my genuine reflections and was carefully reviewed and written by me. This is a crucial exam that will determine my high school placement, so I took this question on stackoverflow very seriously.

I am setting up a captive portal on a single Raspberry Pi (Debian/Raspberry Pi OS) to serve a custom web login page when client smartphones connect to its broadcasted AP.

Network & Environment

  • Hardware: 1 Raspberry Pi with a single wireless interface (wlan0), connected to an upstream network via Ethernet (eth0).

  • Initial Setup & Troubleshooting History:

    1. Installed packages: hostapd, dnsmasq, nginx.

    2. Disabled station Wi-Fi using nmtui / nmcli device disconnect wlan0 to prevent interface contention with the upstream AP, and configured the system over SSH.

    3. Fixed hostapd.service is masked state via systemctl unmask hostapd.

    4. Removed quotes around the SSID name in hostapd.conf to avoid parsing errors.

    5. Resolved DNS wildcard spoofing by testing both address=/192.168.4.1 and address=/#/192.168.4.1 in dnsmasq.conf.

    6. Verified Nginx listening state with ss -tlnp (confirmed active on 0.0.0.0:80).

    7. Configured /etc/nginx/sites-available/default with try_files $uri $uri/ /index.html;.

    8. Attempted HTTP 302 redirection via if ($host != '192.168.4.1') { return 302 [http://192.168.4.1/](http://192.168.4.1/); }.

    9. Added DHCP default gateway and DNS server options (dhcp-option=3,192.168.4.1 and dhcp-option=6,192.168.4.1).

    10. Tested the Android 11+ Captive Portal API standard (RFC 8910) by providing dhcp-option=114,"[http://192.168.4.1/](http://192.168.4.1/)" in dnsmasq.conf.

Configurations

1. /etc/hostapd/hostapd.conf

enter image description here

2. /etc/dnsmasq.conf enter image description here

enter image description here

3. /etc/nginx/sites-available/default

Nginx

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

    root /var/www/html;
    index index.html index.htm;
    server_name _;

    add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0";
    add_header Pragma "no-cache";

    if ($host != '192.168.4.1') {
        return 302 http://192.168.4.1/;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
}

enter image description here

Observed Behaviors & Logs

  1. Direct HTTP Access: Navigating directly to [http://192.168.4.1](http://192.168.4.1) or arbitrary HTTP URLs (e.g., [http://neverssl.com](http://neverssl.com)) successfully routes and loads the local index.html.

  2. HTTPS Requests: Attempting to connect to HTTPS domains returns ERR_CONNECTION_REFUSED since port 443 is closed.

  3. Android Captive Portal Trigger: Android devices connected to the AP do not display the "Sign in to network" notification.

  4. /var/log/nginx/access.log Output:

checked connectivitycheck.android.com/generate_204, www.gstatic.com/generate_204, http:// site, https:// site(failed)

Despite the probing request to /generate_204 receiving a 302 redirect to the portal, the Android OS suppresses the captive portal modal/notification.

What is missing in the DNS, DHCP, or Nginx redirection strategy to reliably force Android to launch the captive portal login screen? enter image description here enter image description here refered: https://hawksites.newpaltz.edu/myerse/2018/06/08/hostapd-on-raspberry-pi/

nginx raspberry-pi captiveportal