Skip to content

feat: nginx config for self hosting #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 29, 2025
Merged
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
47 changes: 13 additions & 34 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
server {
listen 80;
server_name _;
Comment on lines 2 to +3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add default_server or a concrete hostname to avoid name-based routing issues

With server_name _; Nginx will only serve this block when no other server_name matches.
If another vhost is added later, requests may unexpectedly be routed elsewhere.
Safest options:

-listen 80;
+listen 80 default_server;

or replace _ with your real hostname(s) so that routing is explicit.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
listen 80;
server_name _;
listen 80 default_server;
server_name _;


root /var/www/maxun;
index index.html;

# Serve the frontend
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}

location /api {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

# Add timeout configurations
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;

# Add error handling
proxy_intercept_errors on;
error_page 502 503 504 /50x.html;
}

location ~ ^/(record|workflow|storage|auth|integration|proxy|api-docs) {
proxy_pass http://localhost:8080;

# Proxy for backend
location ^/(auth|storage|record|workflow|robot|proxy|api-docs|api)(/|$) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify that the regex location pattern captures all required API endpoints.

The regex pattern ^/(auth|storage|record|workflow|robot|proxy|api-docs|api)(/|$) consolidates multiple API endpoints into a single location block, which is good for maintainability. However, ensure it captures all the backend endpoints your application requires.


🏁 Script executed:

#!/bin/bash
# Verify if there might be other API endpoints in the codebase that should be included in the nginx regex

# Look for API route definitions in the codebase
echo "Searching for potential API routes defined in the codebase..."
rg -g "*.{js,ts,jsx,tsx}" "router\.(get|post|put|delete|patch)\s*\(\s*['\"]\/[^/]+" --json | jq -r ".data.lines.text" | sort | uniq

Length of output: 434


🏁 Script executed:

#!/bin/bash
# Corrected search for API route prefixes in JS/TS files using PCRE
echo "Searching for API route prefixes defined in the codebase..."
rg -P -g '*.{js,ts,jsx,tsx}' "router\.(?:get|post|put|delete|patch)\(\s*['\"]\/([^\/]+)" --only-matching --replace '$1' | sort -u

Length of output: 1975


Update nginx location regex to include missing API prefixes

The current pattern only matches /robot (singular) and doesn’t cover the /robots and /integration routes found in the codebase. Please update the location block on line 14 of nginx.conf to include these:

/robots for the routes in server/src/api/record.ts
/integration for the routes in server/src/routes/integration.ts

Suggested diff:

- location  ^/(auth|storage|record|workflow|robot|proxy|api-docs|api)(/|$) {
+ location  ^/(auth|storage|record|workflow|robots|integration|proxy|api-docs|api)(/|$) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
location ^/(auth|storage|record|workflow|robot|proxy|api-docs|api)(/|$) {
location ^/(auth|storage|record|workflow|robots|integration|proxy|api-docs|api)(/|$) {

proxy_pass http://localhost:8080; # change as per your setup
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'keep-alive'; # Ensure connections remain open
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
Comment on lines 17 to 19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Hard-coding Connection 'upgrade' may break normal HTTP requests

Sending Connection: upgrade on every proxied request can confuse back-ends that do not support WebSockets.
Use the recommended map-based switch instead:

# place this once in the http{} block
map $http_upgrade $connection_upgrade {
    default close;
    websocket upgrade;
}

# inside the location block
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

proxy_cache_bypass $http_upgrade;

# Timeout configurations
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;

# Error handling for these routes
proxy_intercept_errors on;
error_page 502 503 504 /50x.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}