A Orcinus API for generating Nginx configuration files with support for templates, validation, and advanced features.
- 🔧 Pre-defined templates for common setups
- âś… Configuration validation
- đź”’ Advanced SSL/Security configurations
- 🚀 Microservices support
- đź“ť Detailed documentation
- 🔄 WebSocket support
- đź’ľ Caching strategies
- ⚡ Rate limiting
- Install Luwak:
curl -o- https://raw.githubusercontent.com/graphteon/luwak/main/install.sh | bash
- Run the server:
luwak https://github.com/orcinustools/nginx-api/blob/main/main.ts
The server will start on http://localhost:3005
Returns available templates and documentation.
Generates Nginx configuration based on template or custom configuration.
- Static Website
{
"template": "static",
"templateParams": {
"domain": "example.com",
"rootPath": "/var/www/example",
"sslEnabled": true
}
}
- Single Page Application (SPA)
{
"template": "spa",
"templateParams": {
"domain": "myapp.com",
"rootPath": "/var/www/myapp",
"apiUrl": "http://api.myapp.com",
"sslEnabled": true
}
}
- WordPress
{
"template": "wordpress",
"templateParams": {
"domain": "blog.com",
"rootPath": "/var/www/wordpress",
"phpVersion": "8.2",
"sslEnabled": true
}
}
- Microservices
{
"template": "microservices",
"templateParams": {
"domain": "api.myapp.com",
"services": [
{
"name": "auth",
"port": 3001,
"path": "/auth",
"methods": ["POST", "GET"],
"corsEnabled": true
},
{
"name": "users",
"port": 3002,
"path": "/users",
"methods": ["GET", "POST", "PUT", "DELETE"],
"corsEnabled": true
}
],
"sslEnabled": true
}
}
You can also provide a custom configuration:
{
"config": {
"domain": "custom.com",
"serverName": "custom.com www.custom.com",
"port": 443,
"ssl": {
"certificate": "/etc/ssl/custom.com.crt",
"certificateKey": "/etc/ssl/custom.com.key",
"protocols": ["TLSv1.2", "TLSv1.3"],
"forceRedirect": true
},
"security": {
"xFrameOptions": "DENY",
"xContentTypeOptions": true,
"xXSSProtection": true
},
"locations": [
{
"path": "/",
"root": "/var/www/custom",
"index": "index.html"
}
]
}
}
{
"ssl": {
"certificate": "/path/to/cert.pem",
"certificateKey": "/path/to/key.pem",
"protocols": ["TLSv1.2", "TLSv1.3"],
"ciphers": ["ECDHE-ECDSA-AES128-GCM-SHA256"],
"preferServerCiphers": true,
"dhParam": "/path/to/dhparam.pem",
"ocspStapling": true,
"sessionTimeout": "1d",
"hsts": {
"enabled": true,
"maxAge": 31536000,
"includeSubdomains": true,
"preload": true
}
}
}
{
"security": {
"xFrameOptions": "DENY",
"xContentTypeOptions": true,
"xXSSProtection": true,
"referrerPolicy": "strict-origin-when-cross-origin",
"contentSecurityPolicy": [
"default-src 'self'",
"img-src 'self' data: https:",
"script-src 'self' 'unsafe-inline'"
]
}
}
{
"websocket": {
"enabled": true,
"timeout": 3600,
"keepaliveTimeout": 60
}
}
{
"cache": {
"enabled": true,
"validTime": "30m",
"keys": ["$host", "$request_uri"],
"useStale": ["error", "timeout", "updating"],
"minUses": 2,
"bypass": ["$http_cache_control"],
"methods": ["GET", "HEAD"]
}
}
{
"rateLimit": {
"rate": "10r/s",
"burstSize": 20,
"nodelay": true
}
}
{
"cors": {
"enabled": true,
"origins": ["https://example.com"],
"methods": ["GET", "POST", "OPTIONS"],
"headers": ["Authorization", "Content-Type"],
"credentials": true
}
}
main.ts
- Main server filetypes.ts
- TypeScript interfacesvalidator.ts
- Configuration validationgenerator.ts
- Nginx config generationtemplates.ts
- Pre-defined templates
The API validates:
- Domain format
- Port ranges
- SSL configuration
- Security headers
- Rate limit format
- URL formats
- Required fields
Success Response:
{
"success": true,
"config": "... nginx configuration ...",
"fileName": "example.com.conf",
"template": "static"
}
Error Response:
{
"error": "Configuration validation failed",
"validationErrors": [
{
"field": "domain",
"message": "Invalid domain format"
}
]
}
curl -X POST -H "Content-Type: application/json" -d '{
"template": "static",
"templateParams": {
"domain": "example.com",
"rootPath": "/var/www/example",
"sslEnabled": true
}
}' http://localhost:3000
curl -X POST -H "Content-Type: application/json" -d '{
"template": "wordpress",
"templateParams": {
"domain": "blog.com",
"rootPath": "/var/www/wordpress",
"phpVersion": "8.2",
"sslEnabled": true
}
}' http://localhost:3000
curl -X POST -H "Content-Type: application/json" -d '{
"template": "microservices",
"templateParams": {
"domain": "api.myapp.com",
"services": [
{
"name": "auth",
"port": 3001,
"path": "/auth",
"methods": ["POST", "GET"],
"corsEnabled": true
}
],
"sslEnabled": true
}
}' http://localhost:3000
The API provides detailed error messages for:
- Invalid configuration
- Missing required fields
- Invalid template names
- Invalid parameter values
- Server errors
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License