Files
homelab/k8s/apps/syncthing/nginx-router.yaml

282 lines
10 KiB
YAML
Raw Normal View History

apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
namespace: syncthing
data:
default.conf: |
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name _;
# Landing page
location = / {
root /usr/share/nginx/html;
try_files /index.html =404;
}
# NAS instance
location /nas {
rewrite ^/nas$ /nas/ permanent;
}
# NAS API endpoints
location ~ ^/nas/(rest|meta)/ {
rewrite ^/nas/(.*) /$1 break;
proxy_pass http://syncthing-nas:8384;
proxy_set_header Host $host;
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;
# Handle websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
}
location /nas/ {
proxy_pass http://syncthing-nas:8384/;
# Important: tell syncthing that we're using /nas as base path
proxy_set_header Host $host;
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;
# Handle websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
# Sub filter to fix asset paths
sub_filter 'href="/' 'href="/nas/';
sub_filter 'src="/' 'src="/nas/';
sub_filter 'url(/' 'url(/nas/';
sub_filter '"/meta' '"/nas/meta';
sub_filter '"/rest' '"/nas/rest';
sub_filter '"/vendor' '"/nas/vendor';
sub_filter '"/theme-assets' '"/nas/theme-assets';
sub_filter '"/syncthing' '"/nas/syncthing';
# Add floating back button via JavaScript before last script tag
sub_filter '<!-- / gui application code -->' '<!-- / gui application code --><script>window.addEventListener("load", function() { var btn = document.createElement("a"); btn.href = "/"; btn.innerHTML = "← Back to Instances"; btn.style.cssText = "position: fixed; top: 70px; left: 10px; z-index: 10000; background: #0078e7; color: white; padding: 8px 16px; border-radius: 4px; text-decoration: none; display: block; box-shadow: 0 2px 4px rgba(0,0,0,0.2);"; document.body.appendChild(btn); });</script>';
sub_filter_once off;
sub_filter_types text/html text/css application/javascript;
}
# Master instance
location /master {
rewrite ^/master$ /master/ permanent;
}
# Master API endpoints
location ~ ^/master/(rest|meta)/ {
rewrite ^/master/(.*) /$1 break;
proxy_pass http://syncthing-master:8384;
proxy_set_header Host $host;
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;
# Handle websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
}
location /master/ {
proxy_pass http://syncthing-master:8384/;
proxy_set_header Host $host;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
sub_filter 'href="/' 'href="/master/';
sub_filter 'src="/' 'src="/master/';
sub_filter 'url(/' 'url(/master/';
sub_filter '"/meta' '"/master/meta';
sub_filter '"/rest' '"/master/rest';
sub_filter '"/vendor' '"/master/vendor';
sub_filter '"/theme-assets' '"/master/theme-assets';
sub_filter '"/syncthing' '"/master/syncthing';
# Add floating back button via JavaScript before last script tag
sub_filter '<!-- / gui application code -->' '<!-- / gui application code --><script>window.addEventListener("load", function() { var btn = document.createElement("a"); btn.href = "/"; btn.innerHTML = "← Back to Instances"; btn.style.cssText = "position: fixed; top: 70px; left: 10px; z-index: 10000; background: #0078e7; color: white; padding: 8px 16px; border-radius: 4px; text-decoration: none; display: block; box-shadow: 0 2px 4px rgba(0,0,0,0.2);"; document.body.appendChild(btn); });</script>';
sub_filter_once off;
sub_filter_types text/html text/css application/javascript;
}
# Iris instance
location /iris {
rewrite ^/iris$ /iris/ permanent;
}
# Iris API endpoints
location ~ ^/iris/(rest|meta)/ {
rewrite ^/iris/(.*) /$1 break;
proxy_pass http://syncthing-khv:8384;
proxy_set_header Host $host;
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;
# Handle websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
}
location /iris/ {
proxy_pass http://syncthing-khv:8384/;
proxy_set_header Host $host;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
sub_filter 'href="/' 'href="/iris/';
sub_filter 'src="/' 'src="/iris/';
sub_filter 'url(/' 'url(/iris/';
sub_filter '"/meta' '"/iris/meta';
sub_filter '"/rest' '"/iris/rest';
sub_filter '"/vendor' '"/iris/vendor';
sub_filter '"/theme-assets' '"/iris/theme-assets';
sub_filter '"/syncthing' '"/iris/syncthing';
# Add floating back button via JavaScript before last script tag
sub_filter '<!-- / gui application code -->' '<!-- / gui application code --><script>window.addEventListener("load", function() { var btn = document.createElement("a"); btn.href = "/"; btn.innerHTML = "← Back to Instances"; btn.style.cssText = "position: fixed; top: 70px; left: 10px; z-index: 10000; background: #0078e7; color: white; padding: 8px 16px; border-radius: 4px; text-decoration: none; display: block; box-shadow: 0 2px 4px rgba(0,0,0,0.2);"; document.body.appendChild(btn); });</script>';
sub_filter_once off;
sub_filter_types text/html text/css application/javascript;
}
}
index.html: |
<!DOCTYPE html>
<html>
<head>
<title>Syncthing Instances</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.container {
text-align: center;
background: white;
padding: 40px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
margin-bottom: 30px;
}
.links {
display: flex;
flex-direction: column;
gap: 15px;
}
a {
display: inline-block;
padding: 15px 30px;
background-color: #0078e7;
color: white;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s;
}
a:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h1>Syncthing Instances</h1>
<div class="links">
<a href="/nas/">NAS Instance</a>
<a href="/master/">Master Instance</a>
<a href="/iris/">Iris Instance</a>
</div>
</div>
</body>
</html>
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: syncthing-router
namespace: syncthing
spec:
replicas: 1
selector:
matchLabels:
app: syncthing-router
template:
metadata:
labels:
app: syncthing-router
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: config
mountPath: /etc/nginx/conf.d
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: config
configMap:
name: nginx-config
items:
- key: default.conf
path: default.conf
- name: html
configMap:
name: nginx-config
items:
- key: index.html
path: index.html
---
apiVersion: v1
kind: Service
metadata:
name: syncthing-router
namespace: syncthing
spec:
selector:
app: syncthing-router
ports:
- protocol: TCP
port: 80
targetPort: 80