dify发布的url链接通过nginx代理

1.在dify创建的应用然后发布
url如下
http://192.168.12.87/chat/sIfTQI2JsmocX7JL

 

2.走nginx访问

#############################方法1:域名带子路径串访问########################

vi /etc/nginx/conf.d/dify.hxl.com.conf
内容如下:

server {listen 80;server_name www.hxl.com;location / {proxy_pass http://192.168.12.87;
        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;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_connect_timeout 300s;proxy_read_timeout 300s;proxy_send_timeout 300s;}
}

 

若没有www.hxl.com这个域名的情况下,可以在windows下的hosts文件做解析,如下
192.168.1.14 www.hxl.com

 

3.重新应用
nginx -t
nginx -s reload

 

4.浏览器访问
http://www.hxl.com/chat/sIfTQI2JsmocX7JL

 

https版本:

vi /etc/nginx/conf.d/dify.hxl.com.conf

# HTTP 80端口:全部重定向 HTTPS
server {listen 80;server_name www.hxl.com;return 301 https://$host$request_uri;
}# HTTPS 443 ssl 主配置
server {listen 443 ssl;server_name www.hxl.com;# ======================【修改这里!填入你的证书路径】======================ssl_certificate sslkey/_.hxl.com.crt;ssl_certificate_key sslkey/_.hxl.com.key;# ======================================================================# SSL安全优化参数(直接复制不用改)ssl_protocols TLSv1.2 TLSv1.3;ssl_prefer_server_ciphers on;ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;ssl_session_cache shared:SSL:10m;ssl_session_timeout 10m;location / {proxy_pass http://192.168.12.87;
        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;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_connect_timeout 300s;proxy_read_timeout 300s;proxy_send_timeout 300s;}
}

 

https访问
https://www.hxl.com/chat/sIfTQI2JsmocX7JL

 

##################################方法2(使用301重定向)##############################

vi /etc/nginx/conf.d/dify.hxl.com.conf

server {listen 80;server_name www.hxl.com;location = /mychat {return 301 /chat/sIfTQI2JsmocX7JL;}location / {proxy_pass http://192.168.12.87;
        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;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_connect_timeout 300s;proxy_read_timeout 300s;}
}

 

nginx -t
nginx -s reload

浏览器访问:
www.hxl.com/mychat

这样浏览器会自动重定向到如下地址:
http://www.hxl.com/chat/sIfTQI2JsmocX7JL

 

https版本

 

server {listen 80;server_name www.hxl.com;# HTTP全部强制跳转HTTPSreturn 301 https://$host$request_uri;
}server {listen 443 ssl;server_name www.hxl.com;# ========= SSL证书路径,修改为你自己证书 =========ssl_certificate sslkey/_.hxl.com.crt;ssl_certificate_key sslkey/_.hxl.com.key;# SSL优化参数ssl_protocols TLSv1.2 TLSv1.3;ssl_prefer_server_ciphers on;ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;# 短地址入口:https://www.hxl.com/mychatlocation = /mychat {return 301 /chat/sIfTQI2JsmocX7JL;}# 全部流量代理至后端Difylocation / {proxy_pass http://192.168.12.87;
proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# 关键:告诉后端当前是https访问,防止Dify生成http资源地址proxy_set_header X-Forwarded-Proto $scheme;# WebSocket 流式对话必备proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";# 大模型长时间回答超时设置proxy_connect_timeout 300s;proxy_read_timeout 300s;proxy_send_timeout 300s;}
}

 

https 访问:

https://www.hxl.com/mychat