I'm encountering a path rewriting problem when using Docker Compose with Nginx reverse proxy to deploy a Hugo blog. Requests to IP/Hugo-Blog/X/Y/Z are being redirected to IP/X/Y/Z instead of maintaining the /Hugo-Blog/ prefix, resulting in 404 errors.
However, when I try to access IP/Hugo-Blog/X/Y/Z/ directly(with a trailing slash), it works correctly.
The same Hugo structure works correctly on GitHub Pages at https://ri-nai.github.io/Hugo-Blog/.
Setup Details:
- Infrastructure: Tencent Cloud Server (Chinese cloud platform)
- Stack: Docker Compose + Nginx reverse proxy + Hugo static site
Configuration Files:
docker-compose.yaml:
version: '3'
services:
homepage: # Homepage Site, works fine
...
blog:
build: ./Hugo-Blog
container_name: blog
expose:
- "80"
restart: always
reverse-proxy:
image: nginx:stable-alpine
container_name: reverse-proxy
volumes:
- ./nginx-proxy/default.conf:/etc/nginx/conf.d/default.conf:ro
ports:
- "80:80"
depends_on:
- homepage
- blog
restart: always
Hugo-Blog/Dockerfile:
FROM hugomods/hugo:exts-0.128.0 AS builder
COPY . .
RUN hugo --minify --baseURL "https://ri-nai.github.io/Hugo-Blog/"
FROM nginx:stable-alpine
COPY --from=builder /src/public /usr/share/nginx/html
nginx-proxy/default.conf:
server {
listen 80;
server_name IP;
location /Hugo-Blog/ {
proxy_pass http://blog:80/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
proxy_pass http://homepage:80/;
# ... same headers
}
}
Troubleshooting Attempted:
Confirmed Hugo configuration works properly on GitHub Pages
Verified Docker containers are running and accessible internally
Tries and Expects
Request to
IP/Hugo-Blog/about- 404 on
IP/Hugo-Blog/about - Followed by 404 on
IP/about
- 404 on
Expected: Behavior matching GitHub Pages' 301 → 200 redirect pattern while keeping
/Hugo-Blog/prefix