Skip to main content
Glama

nginx_setup

Configure Nginx web server with domain mapping, reverse proxy setup, and SSL certificate installation for secure application deployment.

Instructions

Configure Nginx with domain, reverse proxy, and SSL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
domainYesDomain name
portYesBackend port to proxy to
sslNoEnable SSL with Certbot

Implementation Reference

  • Core handler implementing the nginx_setup tool logic: creates Nginx site config, tests and reloads Nginx, sets up SSL with Certbot if requested, and configures firewall.
    async setupNginx(config: NginxConfig): Promise<NginxResult> {
      try {
        logger.info('Setting up Nginx configuration', { domain: config.domain, port: config.port });
    
        // Create Nginx configuration
        const nginxConfigResult = await this.createNginxConfig(config);
        if (!nginxConfigResult.success) {
          return nginxConfigResult;
        }
    
        // Test and reload Nginx
        const testResult = await this.sshService.executeCommand('nginx -t');
        if (!testResult.success) {
          return {
            success: false,
            message: `Nginx configuration test failed: ${testResult.stderr}`,
          };
        }
    
        const reloadResult = await this.sshService.executeCommand('systemctl reload nginx');
        if (!reloadResult.success) {
          return {
            success: false,
            message: `Failed to reload Nginx: ${reloadResult.stderr}`,
          };
        }
    
        // Setup SSL if requested
        if (config.ssl) {
          const sslResult = await this.setupSSL(config.domain);
          if (!sslResult.success) {
            return sslResult;
          }
        }
    
        // Configure firewall
        await this.configureFirewall();
    
        return {
          success: true,
          message: `Nginx configured successfully for ${config.domain}${config.ssl ? ' with SSL' : ''}`,
        };
      } catch (error) {
        logger.error('Nginx setup failed', { error, config });
        return {
          success: false,
          message: `Nginx setup failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
        };
      }
    }
  • MCP server wrapper handler for 'nginx_setup' tool that validates input with Zod schema and delegates to NginxManager.setupNginx.
    private async handleNginxSetup(
      args: unknown
    ): Promise<{ content: Array<{ type: 'text'; text: string }> }> {
      if (!this.nginxManager) {
        throw new Error('SSH connection not established. Please connect first.');
      }
    
      const config = NginxConfigSchema.parse(args);
      const result = await this.nginxManager.setupNginx(config);
    
      return {
        content: [
          {
            type: 'text',
            text: result.success
              ? `Nginx configured successfully for ${config.domain}`
              : `Nginx setup failed: ${result.message}`,
          },
        ],
      };
    }
  • Registration of the 'nginx_setup' tool in the MCP server's listTools response, defining name, description, and input schema.
    {
      name: 'nginx_setup',
      description: 'Configure Nginx with domain, reverse proxy, and SSL',
      inputSchema: {
        type: 'object',
        properties: {
          domain: { type: 'string', description: 'Domain name' },
          port: { type: 'number', description: 'Backend port to proxy to' },
          ssl: { type: 'boolean', description: 'Enable SSL with Certbot' },
        },
        required: ['domain', 'port'],
      },
    },
  • Zod schema for validating nginx_setup tool input parameters.
    const NginxConfigSchema = z.object({
      domain: z.string().describe('Domain name for Nginx configuration'),
      port: z.number().describe('Backend port to proxy to'),
      ssl: z.boolean().optional().default(true).describe('Enable SSL with Certbot'),
    });
  • Helper method that generates the Nginx server block configuration template with reverse proxy, security headers, gzip, and static file optimization.
      private generateNginxConfig(config: NginxConfig): string {
        return `server {
        listen 80;
        server_name ${config.domain} www.${config.domain};
    
        # Security headers
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Referrer-Policy "no-referrer-when-downgrade" always;
        add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
    
        # Gzip compression
        gzip on;
        gzip_vary on;
        gzip_min_length 1024;
        gzip_proxied expired no-cache no-store private must-revalidate auth;
        gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
    
        location / {
            proxy_pass http://127.0.0.1:${config.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_cache_bypass $http_upgrade;
            proxy_read_timeout 86400;
        }
    
        # Deny access to hidden files
        location ~ /\\. {
            deny all;
        }
    
        # Optimize static file serving
        location ~* \\.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf|svg)$ {
            expires 1y;
            add_header Cache-Control "public, immutable";
            try_files $uri @proxy;
        }
    
        location @proxy {
            proxy_pass http://127.0.0.1:${config.port};
            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;
        }
    }`;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states 'Configure Nginx,' implying a mutation that likely changes system files and requires permissions, but doesn't specify if it's idempotent, destructive, or requires sudo/root access. It mentions SSL with Certbot, hinting at external dependencies, but lacks details on rate limits, error handling, or output format. This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Configure Nginx with domain, reverse proxy, and SSL.' It's front-loaded with the core action and lists key features without redundancy. Every word earns its place, making it highly concise and well-structured for quick comprehension.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of configuring Nginx (a mutation tool with system impact), no annotations, no output schema, and 3 parameters, the description is incomplete. It lacks details on behavioral traits (e.g., permissions, side effects), usage context, and what to expect upon completion (e.g., success message, file changes). The agent is left with significant gaps in understanding how to invoke and interpret results from this tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds minimal meaning beyond the input schema, which has 100% coverage with clear descriptions for 'domain,' 'port,' and 'ssl.' It implies that 'domain' and 'port' are used for reverse proxy setup and 'ssl' enables Certbot, but doesn't elaborate on syntax (e.g., domain format), defaults, or interactions between parameters. With high schema coverage, the baseline is 3, and the description doesn't significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Configure Nginx with domain, reverse proxy, and SSL.' It specifies the verb ('configure') and resources/features (Nginx, domain, reverse proxy, SSL), making the action concrete. However, it doesn't explicitly differentiate from sibling tools like 'vps_initialize' or 'github_cicd_setup', which might also involve configuration tasks, so it misses full sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing Nginx installed), exclusions (e.g., not for Apache setups), or comparisons to siblings like 'execute_command' for general commands or 'vps_initialize' for initial server setup. This leaves the agent without context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/oxy-Op/DevPilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server