您的位置 首页 大模型

dify 配置域名,nginx反向代理

dify 配置域名,nginx反向代理

[dify]NGINX配置代理dify自定义地址访问_dify nginx-CSDN博客

需求:

dify : http://127.0.0.1:81

配置上域名, https://xxx.com/dify

NGINX配置能使得通过nginx的域名+path,如:https://my.com/dify/install 访问到dify

我这边测试后,发现加上dify 后登录可以,但是其他页面有问题, 用的。dify1.4.1版本,估计更新后失效了

实现:

1、dify配置

①修改.env文件

docker目录下找到.env文件,找到EXPOSE_NGINX_PORT,修改EXPOSE_NGINX_PORT和EXPOSE_NGINX_SSL_PORT后面的端口号(后续使用8881端口演示)

# ------------------------------
# Docker Compose Service Expose Host Port Configurations
# ------------------------------
EXPOSE_NGINX_PORT=8881 #80
EXPOSE_NGINX_SSL_PORT=8882 #443

②修改docker.compose.yaml

在docker目录下,找到docker.compose.yaml文件,找到web节点并修改如下配置  增加下面build配置

  # Frontend web application.
  web:
    #增加下面build配置
    build:
      context: ../web
      dockerfile: Dockerfile
    #移除下面这行image
    image: langgenius/dify-web:0.15.3 
    restart: always
    environment:
      CONSOLE_API_URL: ${CONSOLE_API_URL:-}
      APP_API_URL: ${APP_API_URL:-}
      SENTRY_DSN: ${WEB_SENTRY_DSN:-}
      NEXT_TELEMETRY_DISABLED: ${NEXT_TELEMETRY_DISABLED:-0}
      TEXT_GENERATION_TIMEOUT_MS: ${TEXT_GENERATION_TIMEOUT_MS:-60000}
      CSP_WHITELIST: ${CSP_WHITELIST:-}
      TOP_K_MAX_VALUE: ${TOP_K_MAX_VALUE:-}
      INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH:     
      ${INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH:-}

③修改Next.js配置文件

在dify根目录中找到web文件夹下的next.config.js文件,下拉到文件最后,修改如下内容:

  async redirects() {
    return [
      {
        source: '/',
        destination: '/apps',
        permanent: false,
      },
    ]
  },
  output: 'standalone',
  //增加下面一行
  basePath: '/dify', 

④重新启动dify

到docker目录下,依次执行:

docker compose down
docker compose up -d --build

2、NGINX配置

增加如下nginx配置:

location ~* ^/(dify|console|api) {
     proxy_pass http://localhost:8881;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header Host $host:$server_port;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_http_version 1.1;
     add_header 'Access-Control-Allow-Origin' '*'; # 解决 CORS 问题
     add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
     add_header 'Access-Control-Allow-Headers' 'DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type';
        }
#代理/logo资源请求
location /logo/ {
     proxy_pass http://localhost/dify/logo/;
     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;
}
#解决跳转登录404(也可直接在dify页面修改跳转地址)
location /signin/ {
     proxy_pass http://localhost/dify/signin/;
     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;
}

 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章