You are absolutely correct to verify the documentation. I apologize for the previous error—**`nghttpx` does NOT support native Basic Authentication (username/password) for frontend clients.** The option `frontend-http-user` (and `basic-auth-file`) does not exist in the official `nghttpx` documentation.
Since your architecture is **Client -> nghttpx (TLS) -> Squid (Proxy)**, the correct place to handle authentication is in **Squid**, not `nghttpx`.
Here is the corrected, documentation-verified setup.
### 1. The Strategy
We will configure **Squid** to handle the username/password verification. `nghttpx` will simply pass the credentials (the `Proxy-Authorization` header) from the user to Squid.
### 2. Create the Password File
You need a tool like `htpasswd` (from `apache2-utils`) to create a hashed password file. Run this on your host machine:
Bash
```
# Create file 'passwords' with user 'myuser'
htpasswd -c ./passwords myuser
# Enter password when prompted
```
### 3. Update `docker-compose.yml`
You need to mount this password file into the **Squid** service (not nghttpx). You also need to mount a custom `squid.conf`.
YAML
```
services:
# ... nghttpx service remains the same ...
squid:
image: ubuntu/squid:latest
container_name: squid-proxy
restart: always
volumes:
- ./squid.conf:/etc/squid/squid.conf:ro
- ./passwords:/etc/squid/passwords:ro # Mount the password file here
networks:
- internal-net
```
### 4. Create `squid.conf`
Create a `squid.conf` file in the same directory. This configuration enables Basic Authentication using the file we just created.
Code snippet
```
# Define the authentication program
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm My Private Proxy
auth_param basic children 5
auth_param basic credentialsttl 2 hours
# Define the ACL (Access Control List) for authenticated users
acl authenticated_users proxy_auth REQUIRED
# Allow access only to authenticated users
http_access allow authenticated_users
# Deny everything else
http_access deny all
# Listen on port 3128
http_port 3128
```
_(Note: The path `/usr/lib/squid/basic_ncsa_auth` is standard for Ubuntu/Debian based Squid images. If you use Alpine, it might be `/usr/lib/squid/basic_ncsa_auth` or similar, check `apk info -L squid` if it fails)._
### 5. Clean up `nghttpx.conf`
Revert `nghttpx.conf` to its clean state (remove the invalid auth lines). `nghttpx` must be configured to pass the traffic transparently.
Code snippet
```
# nghttpx.conf
# Frontend: Listen on 3000, no TLS (Traefik handles TLS)
frontend=0.0.0.0,3000;no-tls
# Backend: Forward to Squid
backend=squid,3128
# Logs
errorlog-file=/dev/stderr
accesslog-file=/dev/stdout
log-level=INFO
# Essential: Do NOT strip proxy headers, otherwise Squid won't see the password!
strip-incoming-x-forwarded-for=no
```
### 6. Verify and Apply
1.**Restart:**`docker-compose up -d --force-recreate`