Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit 43bff91

Browse files
committed
fix: replace Nginx with Caddy to fix "premature close" error while downloading larger files
1 parent 1aa3d8e commit 43bff91

File tree

5 files changed

+25
-33
lines changed

5 files changed

+25
-33
lines changed

Caddyfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
:3000 {
2+
# Reverse proxy for /api
3+
reverse_proxy /api/* http://localhost:8080 {
4+
header_up X-Forwarded-Host {host}:{server_port}
5+
header_up X-Forwarded-For {remote_host}
6+
header_up X-Forwarded-Proto {scheme}
7+
}
8+
9+
# Reverse proxy for all other requests
10+
reverse_proxy http://localhost:3333 {
11+
header_up X-Forwarded-Host {host}:{server_port}
12+
header_up X-Forwarded-For {remote_host}
13+
header_up X-Forwarded-Proto {scheme}
14+
}
15+
}

Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ RUN npm run build && npm prune --production
3030
FROM node:20-alpine AS runner
3131
ENV NODE_ENV=docker
3232

33-
# Alpine specific dependencies
34-
RUN apk update --no-cache
35-
RUN apk upgrade --no-cache
36-
RUN apk add --no-cache curl nginx
33+
# Install Caddy
34+
RUN apk update --no-cache \
35+
&& apk upgrade --no-cache \
36+
&& apk add --no-cache curl caddy
3737

38-
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
38+
COPY ./Caddyfile /etc/caddy/Caddyfile
3939

4040
WORKDIR /opt/app/frontend
4141
COPY --from=frontend-builder /opt/app/public ./public
@@ -53,9 +53,8 @@ WORKDIR /opt/app
5353

5454
EXPOSE 3000
5555

56-
# Add a health check to ensure the container is healthy
56+
# Health check remains unchanged
5757
HEALTHCHECK --interval=10s --timeout=3s CMD curl -f http://localhost:3000/api/health || exit 1
5858

59-
# Application startup
60-
# HOSTNAME=0.0.0.0 fixes https://github.com/vercel/next.js/issues/51684. It can be removed as soon as the issue is fixed
61-
CMD cp -rn /tmp/img/* /opt/app/frontend/public/img && nginx && PORT=3333 HOSTNAME=0.0.0.0 node frontend/server.js & cd backend && npm run prod
59+
# Application startup updated for Caddy
60+
CMD cp -rn /tmp/img/* /opt/app/frontend/public/img && caddy run --config /etc/caddy/Caddyfile & PORT=3333 HOSTNAME=0.0.0.0 node frontend/server.js & cd backend && npm run prod

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ API_URL=http://localhost:8080 # Set the URL of the backend, default: http://loca
6464
pm2 start --name="pingvin-share-frontend" npm -- run start
6565
```
6666

67-
**Uploading Large Files**: By default, Pingvin Share uses a built-in reverse proxy to reduce the installation steps. However, this reverse proxy is not optimized for uploading large files. If you wish to upload larger files, you can either use the Docker installation or set up your own reverse proxy. An example configuration for Nginx can be found in `/nginx/nginx.conf`.
67+
**Uploading Large Files**: By default, Pingvin Share uses a built-in reverse proxy to reduce the installation steps. However, this reverse proxy is not optimized for uploading large files. If you wish to upload larger files, you can either use the Docker installation or set up your own reverse proxy. An example configuration for Caddy can be found in `./Caddyfile`.
6868

6969
The website is now listening on `http://localhost:3000`, have fun with Pingvin Share 🐧!
7070

frontend/src/pages/api/[...all].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const config = {
1212
const { apiURL } = getConfig().serverRuntimeConfig;
1313

1414
// A proxy to the API server only used in development.
15-
// In production this route gets overridden by nginx.
15+
// In production this route gets overridden by Caddy.
1616
export default (req: NextApiRequest, res: NextApiResponse) => {
1717
httpProxyMiddleware(req, res, {
1818
headers: {

nginx/nginx.conf

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)