<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Chatglm on lategege 的技术博客</title><link>https://lategege.com/tags/chatglm/</link><description>Recent content in Chatglm on lategege 的技术博客</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Thu, 04 May 2023 02:23:50 +0000</lastBuildDate><atom:link href="https://lategege.com/tags/chatglm/index.xml" rel="self" type="application/rss+xml"/><item><title>Chatglm、Stable Diffusion webui反向代理配置</title><link>https://lategege.com/p/chatglm-stable-diffusion-webui%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E9%85%8D%E7%BD%AE/</link><pubDate>Thu, 04 May 2023 02:23:50 +0000</pubDate><guid>https://lategege.com/p/chatglm-stable-diffusion-webui%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E9%85%8D%E7%BD%AE/</guid><description>&lt;!-- wp:paragraph --&gt;
&lt;p&gt;最近在研究AI模型部署，遇到了一些问题，其中一个就是开放外网访问，像Chatglm、Stable Diffusion的webui普遍采用了Gradio这个高度封装的AI WebUI服务。Gradio如果不修改，默认启动后只会监听127.0.0.1，也就是只能本机使用，而对于局域网其他机器来说，肯定是需要访问的，所以需要修改启动脚本，这个启动脚本在不同模型的WebUI中配置大同小异，本质上都是最后在下面的代码中加入了server_name=0.0.0.0&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;
&lt;!-- wp:code --&gt;
&lt;pre class="wp-block-code"&gt;&lt;code&gt;//最终启动都会调用如下函数
demo.queue().launch(inbrowser=True&lt;mark class="has-inline-color has-accent-color" style="background-color:rgba(0, 0, 0, 0)"&gt;,&lt;strong&gt;&lt;em&gt;server_name=0.0.0.0&lt;/em&gt;&lt;/strong&gt;&lt;/mark&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;!-- /wp:code --&gt;
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;1、针对Chatglm，使用方式就是修改目录下面的web_demo.py，找到上面的代码增加server_name即可&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;2、针对Stable Diffusion webui 则可以通过命令参数传入，如果是linux用户，执行./webui.sh --server-name 0.0.0.0 即可&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;上面虽然打通了局域网访问，但是外网访问还需要配置一下，虽然可以通过gradio的share=True参数达到外网访问效果，但是这种效果的本质是内网穿透，是连接到gradio服务器去实现的。如果家里有公网ip，又不想通过别人的服务器来实现，那就需要配置一个反向代理。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;反向代理一般就是nginx，像gradio这种服务，除了http服务外还有websocket服务，所以nginx需要配置两项，一项是默认的location / ，另一项是websocket的 location /queue&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;
&lt;!-- wp:code --&gt;
&lt;pre class="wp-block-code"&gt;&lt;code&gt;server {
 listen 你对外的端口号(ipv4) ssl;
 listen [::]:你对外的端口号(ipv6) ssl;
 server_name 你对外ip地址或者域名;
 ssl_certificate 你的证书链;
 ssl_certificate_key 你的私钥地址;
 location / {
 proxy_connect_timeout 60;
 proxy_read_timeout 60;
 proxy_send_timeout 60;
 proxy_intercept_errors off;
 proxy_http_version 1.1;
 proxy_set_header Host $http_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_pass webui服务的地址:端口号;
&lt;pre&gt;&lt;code&gt;}
location /queue {
 proxy_pass webui服务的地址:端口号;
 proxy_http_version 1.1;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection Upgrade;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;!-- /wp:code --&gt;
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;为什么websocket要配置location /queue 呢，这是我通过浏览器请求的wss地址分析得出的，Gradio的wss都会走/queue这个路径，proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection Upgrade;可以理解为将https协议升级为wss协议。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;
&lt;!-- wp:paragraph --&gt;
&lt;p&gt;通过上面的配置，我们就可以在外网愉快的访问家里部署的AI WEBUI了。&lt;/p&gt;
&lt;!-- /wp:paragraph --&gt;</description></item></channel></rss>