Skip to content

Commit 860e4c1

Browse files
committed
feat: support specific path fixes #2
1 parent 669d4ca commit 860e4c1

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
# Node environment (development | production)
1010
NODE_ENV=production
1111

12+
# Base URL for the application (for sub-path deployments)
13+
# Default: / (root path)
14+
# Example for sub-path: /ui or /registry-ui
15+
# Must start with / and not end with /
16+
# Leave as / if hosting at domain root (e.g., registry-ui.example.com)
17+
# Set to /ui if hosting at sub-path (e.g., example.com/ui)
18+
NUXT_APP_BASE_URL=/
19+
1220
# --------------------------------------------
1321
# Logging Configuration
1422
# --------------------------------------------

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Create a `.env` file in the root directory:
8282
| `NODE_ENV` | Yes | `development` | Environment mode (`development` or `production`) |
8383
| `HOST` | Yes | `127.0.0.1` | Host to bind |
8484
| `PORT` | Yes | `3000` | Port for the application server |
85+
| `NUXT_APP_BASE_URL` | No | `/` | Base URL for sub-path deployments (e.g., `/ui`) |
8586
| `REGISTRY_URL` | Yes | - | URL of your Docker Registry V2 API |
8687
| `REGISTRY_USERNAME` | No | - | Username for registry authentication |
8788
| `REGISTRY_PASSWORD` | No | - | Password for registry authentication |
@@ -183,6 +184,89 @@ networks:
183184
184185
---
185186
187+
### Sub-Path Deployment
188+
189+
If you want to host the application at a sub-path (e.g., `docker.myserver.com/ui`), you have **two options**:
190+
191+
#### Option 1: Configure Reverse Proxy to Strip Path (Recommended)
192+
193+
Configure your reverse proxy to **strip the sub-path** before forwarding to the application:
194+
195+
<details>
196+
<summary><b>Nginx Example - Path Stripping</b></summary>
197+
198+
```nginx
199+
server {
200+
listen 443 ssl http2;
201+
server_name docker.myserver.com;
202+
203+
# Basic Authentication
204+
auth_basic "Docker Registry UI";
205+
auth_basic_user_file /path/to/.htpasswd;
206+
207+
# Registry UI at /ui
208+
location /ui/ {
209+
# Strip /ui prefix before proxying
210+
rewrite ^/ui/(.*) /$1 break;
211+
212+
proxy_pass http://127.0.0.1:3000;
213+
proxy_set_header Host $host;
214+
proxy_set_header X-Real-IP $remote_addr;
215+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
216+
proxy_set_header X-Forwarded-Proto $scheme;
217+
proxy_set_header X-Forwarded-User $remote_user;
218+
}
219+
}
220+
```
221+
222+
</details>
223+
224+
<details>
225+
<summary><b>Caddy Example - Path Stripping</b></summary>
226+
227+
```caddy
228+
docker.myserver.com {
229+
basicauth /ui/* {
230+
admin $2a$14$...
231+
}
232+
233+
handle_path /ui/* {
234+
reverse_proxy 127.0.0.1:3000 {
235+
header_up X-Forwarded-User {remote_user}
236+
}
237+
}
238+
}
239+
```
240+
241+
</details>
242+
243+
#### Option 2: Configure Application Base URL
244+
245+
Set the `NUXT_APP_BASE_URL` environment variable in your application:
246+
247+
```env
248+
NUXT_APP_BASE_URL=/ui
249+
```
250+
251+
**Nginx configuration (no path stripping):**
252+
253+
```nginx
254+
location /ui/ {
255+
proxy_pass http://127.0.0.1:3000/ui/;
256+
# ... other proxy headers
257+
}
258+
```
259+
260+
**Important Notes:**
261+
262+
- `NUXT_APP_BASE_URL` must start with `/` and **not** end with `/`
263+
- Valid: `/ui`, `/registry-ui`, `/docker/ui`
264+
- Invalid: `ui`, `/ui/`, `ui/`
265+
- Option 1 (path stripping) is recommended for simpler application configuration
266+
- Option 2 requires rebuilding the application when changing the path
267+
268+
---
269+
186270
### Docker Deployment
187271

188272
<details>
@@ -202,6 +286,8 @@ services:
202286
- REGISTRY_USERNAME=admin
203287
- REGISTRY_PASSWORD=${REGISTRY_PASSWORD}
204288
- REGISTRY_VERIFY_SSL=true
289+
# For sub-path deployments (e.g., /ui), uncomment and set:
290+
# - NUXT_APP_BASE_URL=/ui
205291
# NO ports exposed - use reverse proxy
206292
restart: unless-stopped
207293
```

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default defineNuxtConfig({
6060
],
6161

6262
app: {
63+
baseURL: process.env.NUXT_APP_BASE_URL || '/',
6364
head: {
6465
charset: 'utf-8',
6566
viewport: 'width=device-width, initial-scale=1',

0 commit comments

Comments
 (0)