You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Django环境下如何修改Docuseal路由前缀为/docuseal/?

解决Docuseal路由前缀配置问题(适配/docuseal/路径)

1. 正确配置Rails路由前缀

如果Docuseal是独立Rails应用,打开config/routes.rb,用scope包裹所有原有路由,统一添加/docuseal前缀:

Rails.application.routes.draw do
  scope '/docuseal' do
    # 保留Docuseal原有所有路由,示例:
    root 'home#index'
    resources :documents
    resources :templates
    # 其他原有路由...
  end
end

如果Docuseal是以Rails引擎形式存在,直接用mount指定前缀:

Rails.application.routes.draw do
  mount Docuseal::Engine => '/docuseal'
end

2. 调整静态资源路径

Rails默认将静态资源路径设为根目录,需修改配置让资源路径带上/docuseal前缀:

  1. 打开config/environments/production.rb(或对应环境的配置文件),添加:
config.relative_url_root = '/docuseal'
  1. 重新编译生产环境静态资源:
RAILS_ENV=production rails assets:precompile

3. 验证Nginx转发配置

确保Nginx对/docuseal/的请求正确转发到Docuseal的Rails服务,配置示例:

location /docuseal/ {
    proxy_pass http://localhost:3000/; # 末尾斜杠必须保留,确保路径映射正确
    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;
}

# 其余请求转发给Django的Gunicorn
location / {
    proxy_pass http://localhost:8000;
    # 其他Django相关配置...
}

4. 修正硬编码路径

部分Docuseal视图或JS文件可能存在硬编码的根路径(比如href="/documents/new"),需改为Rails的URL辅助方法(比如documents_new_path),这样会自动带上/docuseal前缀;如果是JS中的API请求,要把/api/xxx改为/docuseal/api/xxx。

内容的提问来源于stack exchange,提问作者Moonlight

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 17:15:09