python+flask+vue可视化修改nginx配置站点示例代码
代码语言:python
所属分类:其他
代码描述:python+flask+vue可视化修改nginx配置站点示例代码
代码标签: python flask vue 可视化 修改 nginx 配置 站点 示 例代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
from flask import Flask, request, render_template_string, redirect, url_for, flash
# =================配置区域=================
# Nginx 配置目录 (Debian/Ubuntu 标准风格)
SITES_AVAILABLE = '/etc/nginx/sites-available'
SITES_ENABLED = '/etc/nginx/sites-enabled'
# 监听地址和端口
LISTEN_HOST = '0.0.0.0'
LISTEN_PORT = 8010
# =========================================
app = Flask(__name__)
app.secret_key = os.urandom(24) # 用于 Flash 消息
# =================HTML 模板 (嵌入式)=================
HTML_LAYOUT = """
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nginx 简易管理器</title>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.1/css/bootstrap.min.css" rel="stylesheet">
<style>
body { padding-top: 20px; background-color: #f8f9fa; }
.container { max-width: 960px; }
.card { margin-bottom: 20px; box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075); border: none; }
.status-dot { height: 10px; width: 10px; background-color: #bbb; border-radius: 50%; display: inline-block; margin-right: 5px; }
.status-active { background-color: #28a745; }
.status-paused { background-color: #dc3545; }
pre { background: #f4f4f4; padding: 10px; border-radius: 5px; max-height: 300px; overflow-y: auto; }
.editor { font-family: monospace; min-height: 400px; }
</style>
</head>
<body>
<div class="container">
<nav class="navbar navbar-light bg-white rounded p-3 mb-4">
<span class="navbar-brand mb-0 h1">🧩 Nginx 简易可视化管理</span>
<div>
<a href="{{ url_for('index') }}" class="btn btn-outline-primary btn-sm">首页列表</a>
<a href="{{ url_for('add_site') }}" class="btn btn-success btn-sm">+ 新增网站</a>
<a href="{{ url_for('test_and_reload') }}" class="btn btn-warning btn-sm">🔄 重载 Nginx</a>
</div>
</nav>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
{{ message }}
<button type.........完整代码请登录后点击上方下载按钮下载查看















网友评论0