server = WSGIServer('0.0.0.0', 8000, app) server.serve_forever() 7.1 Production Configuration # production_server.py import os from wsgiserver.server import WSGIServer Production settings HOST = os.getenv('WSGI_HOST', '0.0.0.0') PORT = int(os.getenv('WSGI_PORT', 8000)) WORKERS = int(os.getenv('WSGI_WORKERS', 4))
[Install] WantedBy=multi-user.target # Dockerfile FROM python:3.11-slim WORKDIR /app wsgiserver 0.2
def get_metrics(self): return 'total_requests': self.request_count, 'error_requests': self.error_count, 'error_rate': self.error_count / self.request_count if self.request_count else 0 class SecurityMiddleware: """Add security headers and protections""" def __init__(self, app): self.app = app def __call__(self, environ, start_response): def secure_start_response(status, headers, exc_info=None): # Add security headers headers.extend([ ('X-Content-Type-Options', 'nosniff'), ('X-Frame-Options', 'DENY'), ('X-XSS-Protection', '1; mode=block'), ]) return start_response(status, headers, exc_info) return self.app(environ, secure_start_response) Request size limiting MAX_REQUEST_SIZE = 10 * 1024 * 1024 # 10MB server = WSGIServer('0
duration = time.time() - start_time successful = sum(results) server = WSGIServer('0.0.0.0'