ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
Add Nginx /gitea path support for Gitea and update UI
Juan Denis5139fac36036
diff --git a/backend/app/services/git_service.py b/backend/app/services/git_service.pyindex aeb04003..f0484fe6 100644--- a/backend/app/services/git_service.py+++ b/backend/app/services/git_service.py@@ -596,7 +596,8 @@ class GitService:'running': False,'http_port': None,'ssh_port': None,- 'url': None+ 'url': None,+ 'url_path': None}# Check container status@@ -610,7 +611,8 @@ class GitService:'running': running,'http_port': app.port or config.get('http_port'),'ssh_port': config.get('ssh_port'),- 'url': f"http://localhost:{app.port}" if app.port else None,+ 'url_path': '/gitea', # Slug-based URL path+ 'url': f"http://localhost:{app.port}" if app.port else None, # Legacy port-based URL'app_id': app.id,'version': config.get('version', '1.21')}@@ -672,6 +674,7 @@ class GitService:admin_password: str = None) -> Dict:"""Install Gitea as integrated ServerKit service."""from app.services.template_service import TemplateService+ from app.services.nginx_service import NginxService# Check if already installedstatus = cls.get_gitea_status()@@ -701,6 +704,12 @@ class GitService:http_port = variables.get('HTTP_PORT')ssh_port = variables.get('SSH_PORT')+ # Create nginx config for /gitea path+ nginx_result = NginxService.create_gitea_config(int(http_port))+ if not nginx_result.get('success'):+ # Log warning but don't fail - Gitea still works via port+ print(f"Warning: Failed to create Gitea nginx config: {nginx_result.get('error')}")+# Save config with admin credentials and portsconfig = {'admin_user': admin_user,@@ -709,7 +718,8 @@ class GitService:'ssh_port': ssh_port,'db_password': variables.get('DB_PASSWORD'),'installed_at': datetime.now().isoformat(),- 'version': '1.21'+ 'version': '1.21',+ 'url_path': '/gitea'}cls._save_gitea_config(config)@@ -718,6 +728,7 @@ class GitService:'message': 'Gitea installed successfully','http_port': http_port,'ssh_port': ssh_port,+ 'url_path': '/gitea','admin_user': admin_user}@@ -737,12 +748,16 @@ class GitService:from app import dbfrom app.models import Applicationfrom app.services.docker_service import DockerService+ from app.services.nginx_service import NginxServiceapp = Application.query.filter_by(name=cls.GITEA_APP_NAME).first()if not app:return {'success': False, 'error': 'Gitea is not installed'}try:+ # Remove nginx config+ NginxService.remove_gitea_config()+# Stop and remove containersif app.root_path and os.path.exists(app.root_path):DockerService.compose_down(app.root_path, remove_volumes=remove_data)diff --git a/backend/app/services/nginx_service.py b/backend/app/services/nginx_service.pyindex 4f758ba5..9d7b757b 100644--- a/backend/app/services/nginx_service.py+++ b/backend/app/services/nginx_service.py@@ -164,6 +164,44 @@ class NginxService:# Private URL routing templatesPRIVATE_URL_CONFIG_NAME = 'serverkit-private-urls'+ GITEA_CONFIG_NAME = 'serverkit-gitea'++ # Gitea location block for /gitea path+ GITEA_LOCATION_TEMPLATE = '''server {{+ listen 80;+ listen [::]:80;+ server_name _;++ access_log /var/log/nginx/gitea.access.log;+ error_log /var/log/nginx/gitea.error.log;++ # Gitea at /gitea path+ location /gitea/ {{+ proxy_pass http://127.0.0.1:{port}/;+ 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_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_cache_bypass $http_upgrade;+ proxy_read_timeout 86400;+ proxy_connect_timeout 60;+ proxy_send_timeout 60;++ # Required for Gitea WebSocket connections+ proxy_buffering off;+ client_max_body_size 100M;+ }}++ # Handle /gitea without trailing slash+ location = /gitea {{+ return 301 /gitea/;+ }}+}}+'''PRIVATE_URL_LOCATION_TEMPLATE = ''' # Private URL: /p/{slug}location /p/{slug}/ {{@@ -805,3 +843,87 @@ server {{Dict with exists, enabled, content, and URL count"""return cls.get_site_config(cls.PRIVATE_URL_CONFIG_NAME)++ # ==================== GITEA CONFIGURATION ====================++ @classmethod+ def create_gitea_config(cls, port: int) -> Dict:+ """Create Nginx configuration for Gitea at /gitea path.++ Args:+ port: The internal port Gitea is running on++ Returns:+ Dict with success status and message+ """+ try:+ config = cls.GITEA_LOCATION_TEMPLATE.format(port=port)+ config_path = os.path.join(cls.SITES_AVAILABLE, cls.GITEA_CONFIG_NAME)++ # Write config file+ process = subprocess.run(+ ['sudo', 'tee', config_path],+ input=config,+ capture_output=True,+ text=True+ )+ if process.returncode != 0:+ return {'success': False, 'error': f'Failed to write config: {process.stderr}'}++ # Enable the site+ enabled_path = os.path.join(cls.SITES_ENABLED, cls.GITEA_CONFIG_NAME)+ result = subprocess.run(+ ['sudo', 'ln', '-sf', config_path, enabled_path],+ capture_output=True,+ text=True+ )+ if result.returncode != 0:+ return {'success': False, 'error': f'Failed to enable config: {result.stderr}'}++ # Reload Nginx+ reload_result = cls.reload()+ if not reload_result['success']:+ return reload_result++ return {+ 'success': True,+ 'message': 'Gitea nginx config created',+ 'config_path': config_path,+ 'url_path': '/gitea'+ }++ except Exception as e:+ return {'success': False, 'error': str(e)}++ @classmethod+ def remove_gitea_config(cls) -> Dict:+ """Remove Nginx configuration for Gitea.++ Returns:+ Dict with success status and message+ """+ try:+ # Remove symlink+ enabled_path = os.path.join(cls.SITES_ENABLED, cls.GITEA_CONFIG_NAME)+ subprocess.run(['sudo', 'rm', '-f', enabled_path], capture_output=True, text=True)++ # Remove config file+ config_path = os.path.join(cls.SITES_AVAILABLE, cls.GITEA_CONFIG_NAME)+ subprocess.run(['sudo', 'rm', '-f', config_path], capture_output=True, text=True)++ # Reload Nginx+ cls.reload()++ return {'success': True, 'message': 'Gitea nginx config removed'}++ except Exception as e:+ return {'success': False, 'error': str(e)}++ @classmethod+ def get_gitea_config(cls) -> Dict:+ """Get the current Gitea nginx configuration.++ Returns:+ Dict with exists, enabled, content, and path+ """+ return cls.get_site_config(cls.GITEA_CONFIG_NAME)diff --git a/frontend/src/pages/Git.jsx b/frontend/src/pages/Git.jsxindex c70571dd..b4ba3c7d 100644--- a/frontend/src/pages/Git.jsx+++ b/frontend/src/pages/Git.jsx@@ -129,11 +129,21 @@ function Git() {};const openGitea = () => {- if (status?.http_port) {+ // Use slug-based URL (/gitea) if available, fallback to port+ if (status?.url_path) {+ window.open(`${window.location.origin}${status.url_path}`, '_blank');+ } else if (status?.http_port) {window.open(`http://${window.location.hostname}:${status.http_port}`, '_blank');}};+ const getGiteaUrl = () => {+ if (status?.url_path) {+ return `${window.location.origin}${status.url_path}`;+ }+ return `http://${window.location.hostname}:${status?.http_port}`;+ };+if (loading) {return (<div className="page-loading">@@ -242,8 +252,8 @@ function Git() {</svg></div><div className="status-info">- <span className="status-label">HTTP Port</span>- <span className="status-value">{status?.http_port || 'N/A'}</span>+ <span className="status-label">URL Path</span>+ <span className="status-value">{status?.url_path || `/gitea`}</span></div></div><div className="status-card">@@ -309,8 +319,8 @@ function Git() {<span className="info-label">HTTP URL</span><span className="info-value">{status?.running ? (- <a href={`http://${window.location.hostname}:${status.http_port}`} target="_blank" rel="noopener noreferrer">- http://{window.location.hostname}:{status.http_port}+ <a href={getGiteaUrl()} target="_blank" rel="noopener noreferrer">+ {getGiteaUrl()}</a>) : 'Server not running'}</span>@@ -353,11 +363,11 @@ function Git() {<h3>HTTP Access</h3><p className="text-muted">Access Gitea through your web browser</p><div className="access-url">- <code>http://{window.location.hostname}:{status?.http_port}</code>+ <code>{getGiteaUrl()}</code><buttonclassName="btn btn-sm btn-secondary"onClick={() => {- navigator.clipboard.writeText(`http://${window.location.hostname}:${status?.http_port}`);+ navigator.clipboard.writeText(getGiteaUrl());toast.success('URL copied');}}>