From 7af958b2a2855aaba9168c9cbf35bea7e1e0f71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Fri, 13 Dec 2024 11:56:52 +0100 Subject: [PATCH 1/2] Add more hostname config Should have been part of d42bd66bd0f68b8467b0d2444cb1cdc307b6bff0 --- context/nextjs/etc/nginx/templates/default.conf.template | 3 +++ context/storybook/etc/nginx/templates/default.conf.template | 3 +++ 2 files changed, 6 insertions(+) diff --git a/context/nextjs/etc/nginx/templates/default.conf.template b/context/nextjs/etc/nginx/templates/default.conf.template index be521b1..1e5a53b 100644 --- a/context/nextjs/etc/nginx/templates/default.conf.template +++ b/context/nextjs/etc/nginx/templates/default.conf.template @@ -6,6 +6,9 @@ server { location / { proxy_pass ${NGINX_PROXY_PASS}; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /_next/webpack-hmr { diff --git a/context/storybook/etc/nginx/templates/default.conf.template b/context/storybook/etc/nginx/templates/default.conf.template index 7e7ec07..dc7e168 100644 --- a/context/storybook/etc/nginx/templates/default.conf.template +++ b/context/storybook/etc/nginx/templates/default.conf.template @@ -6,6 +6,9 @@ server { location / { proxy_pass ${NGINX_PROXY_PASS}; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /__webpack-hmr { From 98eacd904866871b6e4d1742cb11916f56070cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Fri, 13 Dec 2024 12:00:04 +0100 Subject: [PATCH 2/2] Add configuration for Vite --- Dockerfile | 9 ++++++++ README.md | 21 +++++++++++++++++++ .../etc/nginx/templates/default.conf.template | 18 ++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 context/vite/etc/nginx/templates/default.conf.template diff --git a/Dockerfile b/Dockerfile index d0cf6fb..40092fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,15 @@ FROM base AS proxy COPY /proxy / +## +# Vite +## +FROM proxy AS vite + +COPY /vite / + +ENV NGINX_PROXY_PASS=http://app:5173 + ## # NextJS ## diff --git a/README.md b/README.md index fa652ca..46e289e 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ environment: This nginx proxy comes with three predefined configurations: - Proxy +- Vite - Next.js - Storybook - Drupal @@ -95,6 +96,26 @@ environment: NGINX_PROXY_PASS: ``` +### Vite + +Vite is like the proxy configuration but also forwards all WebSocket +requests. + +```yaml +image: ghcr.io/reload/https-proxy:vite +``` + +See the configuration details in +[`context/vite/etc/nginx/templates/default.conf.template`](context/nextjs/etc/vite/templates/default.conf.template). + +Use can use the following configuration in your `docker-compose.yml`: + +```yaml +environment: + NGINX_DOCUMENT_ROOT: /var/www/web + NGINX_PROXY_PASS: http://app:5173 +``` + ### Next.js Next.js is like the proxy configuration but also forwards WebSocket diff --git a/context/vite/etc/nginx/templates/default.conf.template b/context/vite/etc/nginx/templates/default.conf.template new file mode 100644 index 0000000..c8a4f15 --- /dev/null +++ b/context/vite/etc/nginx/templates/default.conf.template @@ -0,0 +1,18 @@ +server { + + include include.d/ssl.conf; + + root ${NGINX_DOCUMENT_ROOT}; + + location / { + proxy_pass ${NGINX_PROXY_PASS}; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + # WebSocket proxy + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_read_timeout 86400; + } +}