apache-mcp.conf•2.9 kB
# Apache Configuration for MCP OpenAPI Server Proxy
# Place this in your Apache configuration or include it in your virtual host
# Enable required modules (add to main Apache config if not already enabled)
# LoadModule proxy_module modules/mod_proxy.so
# LoadModule proxy_http_module modules/mod_proxy_http.so
# LoadModule headers_module modules/mod_headers.so
<Location "/mcp">
# Enable proxy
ProxyPreserveHost On
ProxyPass http://localhost:8020/
ProxyPassReverse http://localhost:8020/
# Handle WebSocket upgrades and streaming connections
ProxyPassReverse /
# Set proper headers for MCP communication
ProxyPassReverse /
ProxyPreserveHost On
# Enable CORS headers for cross-origin requests
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"
Header always set Access-Control-Allow-Headers "Content-Type, Accept, Authorization, X-OpenAPI-Base-URL, X-OpenAPI-Bearer-Token, Mcp-Session-Id"
Header always set Access-Control-Max-Age "3600"
# Handle preflight OPTIONS requests
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
# Preserve original request information
ProxyAddHeaders On
# Log proxy requests for debugging
LogLevel proxy:debug
</Location>
# Specific handling for MCP message endpoint
<Location "/mcp/message">
# All the same proxy settings
ProxyPass http://localhost:8020/message
ProxyPassReverse http://localhost:8020/message
# Additional headers for streaming support
Header always set Cache-Control "no-cache, no-store, must-revalidate"
Header always set Pragma "no-cache"
Header always set Expires "0"
# Support for Server-Sent Events if needed
Header always set Connection "keep-alive"
# Disable buffering for streaming responses
SetEnv proxy-nokeepalive 1
SetEnv proxy-sendcl 1
</Location>
# Health check endpoint
<Location "/mcp/health">
ProxyPass http://localhost:8020/health
ProxyPassReverse http://localhost:8020/health
</Location>
# Optional: Redirect root /mcp to /mcp/health for status checking
<Location "/mcp/">
RewriteEngine On
RewriteRule ^/?$ /mcp/health [R=302,L]
</Location>
# Security settings (optional but recommended)
<Location "/mcp">
# Limit request size (adjust as needed)
#LimitRequestBody 10485760 # 10MB
# Rate limiting (if mod_evasive is available)
# DOSHashTableSize 2048
# DOSPageCount 5
# DOSPageInterval 1
# DOSSiteCount 50
# DOSSiteInterval 1
# DOSBlockingPeriod 60
# Optional: Basic authentication (uncomment if needed)
# AuthType Basic
# AuthName "MCP Server Access"
# AuthUserFile /path/to/.htpasswd
# Require valid-user
</Location>