Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__pycache__/
.nginx/*.pem
.nginx/*.log
.nginx/*.pid
.nginx/nginx.generated.conf
88 changes: 88 additions & 0 deletions .nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
worker_processes 1;
error_log NGINX_DIR/error.log;
pid NGINX_DIR/nginx.pid;

events {
worker_connections 64;
}

http {
include MIME_TYPES_PATH;
default_type application/octet-stream;

access_log NGINX_DIR/access.log;

# HTTPS server (port 8443) — needed for WebXR
server {
listen 8443 ssl;
server_name localhost;

ssl_certificate NGINX_DIR/cert.pem;
ssl_certificate_key NGINX_DIR/key.pem;

root PROJECT_ROOT;
index tracker3d-visionpro.html;

# Reverse proxy the tracker API so Vision Pro only needs one HTTPS port
location /api/ {
proxy_pass http://127.0.0.1:8765/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 3s;
proxy_read_timeout 10s;
add_header Access-Control-Allow-Origin *;
}

# WebSocket proxy
location /ws/ {
proxy_pass http://127.0.0.1:8766/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}

location / {
try_files $uri $uri/ =404;
add_header Access-Control-Allow-Origin *;
}
}

# HTTP server (port 8080) — for quick testing without SSL warnings
server {
listen 8080;
server_name localhost;

root PROJECT_ROOT;
index tracker3d-visionpro.html;

location /api/ {
proxy_pass http://127.0.0.1:8765/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 3s;
proxy_read_timeout 10s;
add_header Access-Control-Allow-Origin *;
}

# WebSocket proxy
location /ws/ {
proxy_pass http://127.0.0.1:8766/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}

location / {
try_files $uri $uri/ =404;
add_header Access-Control-Allow-Origin *;
}
}
}
39 changes: 39 additions & 0 deletions .nginx/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Detect mime.types location
if [ -f /opt/homebrew/etc/nginx/mime.types ]; then
MIME_TYPES_PATH="/opt/homebrew/etc/nginx/mime.types"
elif [ -f /usr/local/etc/nginx/mime.types ]; then
MIME_TYPES_PATH="/usr/local/etc/nginx/mime.types"
elif [ -f /etc/nginx/mime.types ]; then
MIME_TYPES_PATH="/etc/nginx/mime.types"
else
echo "Error: Could not find nginx mime.types. Install nginx or set MIME_TYPES_PATH manually."
exit 1
fi

# Generate self-signed cert if missing
if [ ! -f "$SCRIPT_DIR/cert.pem" ] || [ ! -f "$SCRIPT_DIR/key.pem" ]; then
echo "Generating self-signed SSL certificate..."
openssl req -x509 -newkey rsa:2048 -keyout "$SCRIPT_DIR/key.pem" \
-out "$SCRIPT_DIR/cert.pem" -days 365 -nodes \
-subj "/CN=localhost" 2>/dev/null
echo "Certificate created at $SCRIPT_DIR/cert.pem"
fi

# Generate nginx.conf from template
sed -e "s|NGINX_DIR|$SCRIPT_DIR|g" \
-e "s|PROJECT_ROOT|$PROJECT_ROOT|g" \
-e "s|MIME_TYPES_PATH|$MIME_TYPES_PATH|g" \
"$SCRIPT_DIR/nginx.conf" > "$SCRIPT_DIR/nginx.generated.conf"

echo "Generated: $SCRIPT_DIR/nginx.generated.conf"
echo ""
echo "Start nginx with:"
echo " nginx -c $SCRIPT_DIR/nginx.generated.conf"
echo ""
echo "Then open: https://localhost:8443/tracker3d-visionpro.html"
Loading