Merge pull request 'Change nginx setting for handling mesh funnel domain' (#8) from betterNginx into main
Reviewed-on: http://203.171.20.94:3000/PhuongDM/TTMT.ManageWebGUI/pulls/8
This commit is contained in:
commit
1b7d65b155
119
nginx/nginx.conf
119
nginx/nginx.conf
|
|
@ -3,6 +3,7 @@
|
||||||
# server 127.0.0.1:8080;
|
# server 127.0.0.1:8080;
|
||||||
# server 172.18.10.8:8080;
|
# server 172.18.10.8:8080;
|
||||||
# }
|
# }
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name comp.soict.io;
|
server_name comp.soict.io;
|
||||||
|
|
@ -12,72 +13,117 @@ server {
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
# root /usr/share/nginx/html;
|
|
||||||
# index index.html index.htm;
|
|
||||||
return 301 https://$host$request_uri;
|
return 301 https://$host$request_uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server{
|
server {
|
||||||
listen 443 ssl;
|
listen 443 ssl;
|
||||||
server_name comp.soict.io;
|
server_name comp.soict.io;
|
||||||
|
|
||||||
ssl_certificate /etc/letsencrypt/live/comp.soict.io/fullchain.pem;
|
ssl_certificate /etc/letsencrypt/live/comp.soict.io/fullchain.pem;
|
||||||
ssl_certificate_key /etc/letsencrypt/live/comp.soict.io/privkey.pem;
|
ssl_certificate_key /etc/letsencrypt/live/comp.soict.io/privkey.pem;
|
||||||
|
|
||||||
ssl_protocols TLSv1.2 TLSv1.3;
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
ssl_ciphers HIGH:!aNULL:!MD5;
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
|
||||||
|
# MeshCentral proxied flow can set sizable auth cookies.
|
||||||
|
client_header_buffer_size 16k;
|
||||||
|
large_client_header_buffers 8 32k;
|
||||||
|
|
||||||
|
# Required when proxy_pass uses variables.
|
||||||
|
# In Docker, 127.0.0.11 is the embedded DNS resolver.
|
||||||
|
resolver 127.0.0.11 valid=30s ipv6=off;
|
||||||
|
resolver_timeout 5s;
|
||||||
|
|
||||||
set $backend_server 172.18.10.8:8080;
|
set $backend_server 172.18.10.8:8080;
|
||||||
set $meshserver 172.18.10.8:8082;
|
# Internal MeshCentral hop to avoid upstream TLS handshake instability.
|
||||||
# MeshCentral traffic should go through backend proxy controller
|
set $meshserver meshcentral:8082;
|
||||||
# (api/meshcentral/proxy/*) for consistent auth/cookie/header handling.
|
# Public host MeshCentral expects in Host header.
|
||||||
|
set $meshhost soict-overleaf.tailc51e09.ts.net;
|
||||||
|
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
# Default file to serve for directory requests
|
|
||||||
index index.html index.htm;
|
index index.html index.htm;
|
||||||
|
|
||||||
location / {
|
# MeshCentral auth entrypoint. If iframe/browser lands on /login due to
|
||||||
# Try to serve the requested file directly ($uri)
|
# redirect, keep it on MeshCentral instead of frontend routing.
|
||||||
# If it's a directory, try serving the index file ($uri/)
|
location = /login {
|
||||||
# If neither exists, fall back to serving /index.html
|
proxy_pass http://$meshserver;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $meshhost;
|
||||||
|
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;
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
|
||||||
|
proxy_cookie_path / "/; HTTPOnly; Secure; SameSite=None";
|
||||||
|
proxy_read_timeout 3600s;
|
||||||
|
proxy_send_timeout 3600s;
|
||||||
|
proxy_buffering off;
|
||||||
|
}
|
||||||
|
|
||||||
|
# MeshCentral may redirect to "/" with remote params after login.
|
||||||
|
# Detect those requests and proxy them to MeshCentral instead of SPA.
|
||||||
|
location = / {
|
||||||
|
if ($arg_node != "") {
|
||||||
|
rewrite ^ /__mesh_root_proxy__ last;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arg_viewmode != "") {
|
||||||
|
rewrite ^ /__mesh_root_proxy__ last;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arg_gotonode != "") {
|
||||||
|
rewrite ^ /__mesh_root_proxy__ last;
|
||||||
|
}
|
||||||
|
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /__mesh_root_proxy__ {
|
||||||
|
proxy_pass http://$meshserver;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $meshhost;
|
||||||
|
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;
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
|
||||||
|
proxy_cookie_path / "/; HTTPOnly; Secure; SameSite=None";
|
||||||
|
proxy_read_timeout 3600s;
|
||||||
|
proxy_send_timeout 3600s;
|
||||||
|
proxy_buffering off;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Optional: Add cache control headers for static assets for better performance
|
|
||||||
location ~* \.(?:css|js|jpg|jpeg|gif|png|ico|svg|webp)$ {
|
location ~* \.(?:css|js|jpg|jpeg|gif|png|ico|svg|webp)$ {
|
||||||
expires 1y;
|
expires 1y;
|
||||||
add_header Cache-Control "public";
|
add_header Cache-Control "public";
|
||||||
access_log off; # Optional: Don't log accesses for static files
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://$backend_server;
|
proxy_pass http://$backend_server;
|
||||||
|
|
||||||
# Cho phép upload file lớn (vd: 200MB)
|
|
||||||
client_max_body_size 200M;
|
client_max_body_size 200M;
|
||||||
|
|
||||||
# Truyền thẳng stream sang backend
|
|
||||||
proxy_request_buffering off;
|
proxy_request_buffering off;
|
||||||
|
|
||||||
# Tăng timeout khi upload
|
|
||||||
proxy_read_timeout 300s;
|
proxy_read_timeout 300s;
|
||||||
proxy_connect_timeout 300s;
|
proxy_connect_timeout 300s;
|
||||||
proxy_send_timeout 300s;
|
proxy_send_timeout 300s;
|
||||||
|
|
||||||
# CORS headers - Comment vi da xu ly o backend C#
|
|
||||||
# add_header 'Access-Control-Allow-Origin' '*' always;
|
|
||||||
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
||||||
# add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
||||||
|
|
||||||
if ($request_method = OPTIONS) {
|
if ($request_method = OPTIONS) {
|
||||||
return 204;
|
return 204;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api/Sse/events {
|
location /api/Sse/events {
|
||||||
proxy_pass http://$backend_server/api/Sse/events;
|
proxy_pass http://$backend_server/api/Sse/events;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
# cần thiết cho SSE
|
|
||||||
proxy_set_header Connection '';
|
proxy_set_header Connection '';
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
proxy_cache off;
|
proxy_cache off;
|
||||||
|
|
@ -85,18 +131,15 @@ server{
|
||||||
}
|
}
|
||||||
|
|
||||||
# MeshCentral client builds WebSocket URL from current location,
|
# MeshCentral client builds WebSocket URL from current location,
|
||||||
# e.g. wss://comp.soict.io/control.ashx. Route these root endpoints
|
# e.g. wss://comp.soict.io/control.ashx.
|
||||||
# to meshserver so browser URL stays on comp.soict.io while upstream
|
|
||||||
# is forced to 172.18.10.8:8082.
|
|
||||||
location ~ ^/(control|meshrelay|commander|mesh)\.ashx$ {
|
location ~ ^/(control|meshrelay|commander|mesh)\.ashx$ {
|
||||||
proxy_pass https://$meshserver;
|
proxy_pass http://$meshserver;
|
||||||
proxy_ssl_verify off;
|
|
||||||
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $meshhost;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
@ -112,18 +155,22 @@ server{
|
||||||
}
|
}
|
||||||
|
|
||||||
location ^~ /api/meshcentral/proxy/ {
|
location ^~ /api/meshcentral/proxy/ {
|
||||||
# Forward to backend MeshCentralProxyController (api/meshcentral/proxy/*)
|
# Forward directly to MeshCentral, but strip proxy prefix first.
|
||||||
# so backend can handle MeshCentral auth/session consistently.
|
# Without this, upstream sees /api/meshcentral/proxy/* and can redirect-loop.
|
||||||
proxy_pass http://$backend_server;
|
rewrite ^/api/meshcentral/proxy/(.*)$ /$1 break;
|
||||||
|
proxy_pass http://$meshserver;
|
||||||
proxy_cookie_path / "/; HTTPOnly; Secure; SameSite=None";
|
proxy_cookie_path / "/; HTTPOnly; Secure; SameSite=None";
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $meshhost;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_set_header X-Forwarded-Host $host;
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
|
||||||
# Cấu hình WebSocket/SSE cho MeshCentral
|
# Keep browser navigation under /api/meshcentral/proxy/*.
|
||||||
|
proxy_redirect ~^https?://[^/]+(/.*)$ /api/meshcentral/proxy$1;
|
||||||
|
proxy_redirect ~^(/.*)$ /api/meshcentral/proxy$1;
|
||||||
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user