ragflow.conf


Overview

The ragflow.conf file is an Nginx server configuration file designed to serve the frontend assets of the Ragflow web application and to proxy API requests to the backend service. It primarily configures HTTP settings such as gzip compression, static file caching, and routing rules for frontend and API endpoints.

This configuration ensures efficient delivery of static files (JavaScript, CSS, media), enables compression to reduce bandwidth, and directs API requests to the appropriate backend server.


Detailed Explanation

Server Block

server {
    listen 80;
    server_name _;
    root /ragflow/web/dist;

    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";

    location ~ ^/(v1|api) {
        proxy_pass http://ragflow:9380;
        include proxy.conf;
    }

    location / {
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location ~ ^/static/(css|js|media)/ {
        expires 10y;
        access_log off;
    }
}

Configuration Directives and Their Purpose

1. listen 80;

2. server_name _;

3. root /ragflow/web/dist;


Gzip Compression Configuration

Implementation detail: This configuration optimizes bandwidth usage for supported clients by compressing responses, improving page load times.


Location Blocks

1. API Proxy Location

location ~ ^/(v1|api) {
    proxy_pass http://ragflow:9380;
    include proxy.conf;
}

Implementation detail: Using a regex location for versioned API paths allows flexible routing for backend endpoints.


2. Frontend Root Location

location / {
    index index.html;
    try_files $uri $uri/ /index.html;
}

3. Static Assets Cache Location

location ~ ^/static/(css|js|media)/ {
    expires 10y;
    access_log off;
}

Interaction with Other Parts of the System


Usage Examples

1. Accessing the Frontend

2. API Request Proxying


Important Implementation Details


Mermaid Diagram

flowchart TD
    A[Incoming HTTP Request] --> B{URI Match}
    B -->|Starts with /v1 or /api| C[Proxy to Backend at ragflow:9380]
    B -->|Starts with /static/css, /static/js, /static/media| D[Serve Static Asset with 10y Cache]
    B -->|Other URIs| E[Try Files: Serve File or Directory]
    E -->|Not Found| F[Serve /index.html (SPA Fallback)]

Summary

The ragflow.conf file is a focused Nginx configuration for serving a modern web application with:

It acts as a critical bridge between users and the Ragflow application, managing HTTP traffic efficiently and reliably.