ragflow.https.conf


Overview

The ragflow.https.conf file is an Nginx configuration file designed to securely serve the Ragflow web application over HTTPS. It manages HTTP to HTTPS redirection, SSL termination, static asset caching, gzip compression, and reverse proxying API requests to the backend service. This file ensures that all client requests are served efficiently, securely, and reliably while enabling modern web features such as caching and compression.


Detailed Explanation

Server Blocks

The configuration consists of two server blocks:


1. HTTP Server Block (Port 80)

server {
    listen 80;
    server_name your-ragflow-domain.com;
    return 301 https://$host$request_uri;
}

Usage: This block enforces secure connections by redirecting any HTTP requests to HTTPS.


2. HTTPS Server Block (Port 443)

server {
    listen 443 ssl;
    server_name your-ragflow-domain.com;

    ssl_certificate /etc/nginx/ssl/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/privkey.pem;

    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;
    }
}

Explanation of Directives:


Important Implementation Details


Interaction with Other System Components


Usage Examples

Deploying Ragflow with This Configuration

  1. Place this configuration file under /etc/nginx/conf.d/ragflow.https.conf or include it in your main Nginx config.

  2. Ensure SSL certificates are present at /etc/nginx/ssl/fullchain.pem and /etc/nginx/ssl/privkey.pem.

  3. Make sure the Ragflow backend service is accessible at http://ragflow:9380.

  4. Place the frontend build files in /ragflow/web/dist.

  5. Reload or restart Nginx to apply changes:

    sudo nginx -t && sudo systemctl reload nginx
    
  6. Access the application at https://your-ragflow-domain.com.


Mermaid Diagram: Flowchart of Request Handling

flowchart TD
    A[Client Request] -->|HTTP (port 80)| B[HTTP Server Block]
    B -->|301 Redirect| C[Client Redirect to HTTPS]
    A -->|HTTPS (port 443)| D[HTTPS Server Block]
    D --> E{Request URI}
    E -->|/^\/(v1|api)/| F[Proxy to Backend API (http://ragflow:9380)]
    E -->|/^\/static\/(css|js|media)/| G[Serve Static Files with 10y Cache]
    E -->|Other URIs| H[Serve Frontend Files]
    H --> I[try_files $uri $uri/ /index.html]

Explanation:


Summary

This Nginx configuration file is central to deploying the Ragflow web application securely and efficiently. It implements HTTPS enforcement, static asset optimization, SPA routing, and backend API proxying, integrating the frontend and backend seamlessly. The configuration is designed for production environments with security, performance, and maintainability in mind.