# n8n - Optimization and Configuration

n8n - Optimization and Configuration – Self-hosting guide on your NexoraHost server.

In this guide, we will help you optimize your n8n server and reduce server load.

## 1. Recommended System Resources

For optimal performance of n8n, it is recommended to use the following resources:

    - **CPU:** At least 4 cores, better depending on the number of workflows and nodes.
- **RAM:** 8-16 GB for smaller installations, 32 GB or more for larger workflows and many node connections.
- **Storage:** NVMe SSD recommended to avoid lags.

## 2. Environment Configuration of n8n

In this section, you will learn how to configure and optimize n8n.

    - **Configure the Node.js Server:**
<code>
    # Set the maximum amount of memory (RAM) for the n8n server
    export NODE_OPTIONS="--max-old-space-size=4096"

    # Start the n8n server with optimizations
    yarn start --max-old-space-size=4096
    </code>

    - **Configure the .env File:**

        - Edit the file `.n8n/.env` in a text editor.
- Add configurations to improve performance. For example:
<code>
        # Optimize the Node.js Heap
        NODE_OPTIONS="--max-old-space-size=4096"

        # Disable unnecessary warnings
        N8N_LOGGING_LEVEL="warn"
        </code>
    

    - **Optimize the User Interface:**

        - Configure the user interface to deactivate unnecessary UI components.
<code>
        # Disable the Sidebar Command Wizard
        N8N_HIDE_SIDEBAR_COMMANDS=true

        # Disable the authentication warning feature (if not needed)
        N8N_DISABLE_AUTHENTICATION_WARNING=true
        </code>
    

    - **Optimize Workflows:**

        - Minimize the Workflow Planner to remove unnecessary workflows and improve performance.
<code>
        # Minimize the Workflow Planner
        n8n planer minimize
        </code>
    

## 3. Network Component Optimization (Optional)

To enhance performance, you can configure network components like Nginx:

    - **Install and Configure Nginx:**
<code>
    # Install Nginx (example for Debian/Ubuntu)
    sudo apt-get update
    sudo apt-get install nginx

    # Configure Nginx to forward the n8n server
    sudo nano /etc/nginx/sites-available/n8n
    </code>

    - **Edit Configuration File:**
<code>
    server {
        listen 80;
        server_name your_domain_or_ip;

        location / {
            proxy_pass http://localhost:5678;
            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;
        }
    }
    </code>

    - **Test and Enable the Configuration:**
<code>
    sudo nginx -t
    sudo systemctl restart nginx
    </code>

## 4. Performance Optimization

In this section, you will find instructions for improving performance:

    - **Edit the Performance Configuration in .n8n/.n8n.config.js:**
<code>
    const config = {
        // Set the logging level
        logging: "warn",

        // Configure the Workflow Planner
        planerMinimize: true,

        // Disable unnecessary features
        disableAuthenticationWarning: true,
    };
    </code>

## 5. Debugging and Troubleshooting

In this section, you will find instructions for debugging:

    - **Job Management:**
<code>
    Navigate to "Jobs" in the left navigation, to view and manage jobs.
    </code>

    - **Log Files:**

        - Navigate to the log file in the .n8n directory.
- Read the logs to identify and fix errors.

## 6. Conclusion

You have successfully optimized and configured n8n. This guide serves as a reference for further configurations and optimizations.
