东莞优化seo网站关键词优化,信阳市住房和城乡建设厅网站,了解网站建设规划流程,广东湛江免费做网站在Gradio中使用shareTrue会生成一个可用于分享的外链#xff0c;可由于所有外链都走的是Gradio提供的服务器#xff0c;所以生成的应用的响应速度会很慢#xff0c;甚至到了影响正常使用的程度。Gradio官方文档中提供了使用Nginx的方法#xff1a;链接。但现有的大部分算力…在Gradio中使用shareTrue会生成一个可用于分享的外链可由于所有外链都走的是Gradio提供的服务器所以生成的应用的响应速度会很慢甚至到了影响正常使用的程度。Gradio官方文档中提供了使用Nginx的方法链接。但现有的大部分算力集群没有使用systemd而是使用s6作为进程管理工具也就无法使用systemctl来实现一些常用操作。
可以使用下面的命令查看服务器的进程管理方式
ps -p 1 -o comm如果输出为systemd那么可以使用systemctl来实现Nginx的各项操作如果输出为s6-svscan可以参考本文的方式。
下面以我常用的算力平台FunHPC为例开放端口8000一定要确定你使用的平台支持暴露服务端口。
整个过程可以概括为在Ubuntu服务器上部署Nginx作为反向代理配置Nginx监听一个特定的内部端口(8000)该端口已由FunHPC平台映射至公网地址通过平台暴露端口并将所有外部访问流量转发至在另一个内部端口(7860)上运行的Gradio应用。
安装sudo
apt-get install sudo更新apt包安装Nginx
sudo apt update
sudo apt install nginx使用s6启动Nginx
nginx -g daemon off;启动Nginx后这个终端窗口就被占用了需要打开另一个终端继续下面的操作。
查看nginx状态
sudo nginx -t参考输出
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful在FunHPC开放8000端口得到外链。
如https://5awep1xoy9ga5urskya100.deepln.com:30499。
创建Nginx站点配置文件
sudo nano /etc/nginx/sites-available/your_gradio_appGradio的默认端口是7860Nginx监听的端口是8000所以配置文件中只需要根据你的应用需求修改client_max_body_size即可文件内容
server {listen 8000; # 在FunHPC平台上暴露的内部端口listen [::]:8000;access_log /var/log/nginx/gradio_8000.access.log;error_log /var/log/nginx/gradio_8000.error.log;client_max_body_size 20M; # 客户端最大上传文件大小location / { # 直接通过平台提供的外链访问proxy_pass http://127.0.0.1:7860/; # Gradio运行的端口proxy_buffering off;proxy_redirect off;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection upgrade;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 https;proxy_set_header X-Forwarded-Host $http_host; }
}启用站点配置
sudo ln -s /etc/nginx/sites-available/your_gradio_app /etc/nginx/sites-enabled/找到现在的Nginx进程并关闭
ps aux | grep nginx: master process一般执行完上面的语句后会出现两个进程例如
root 3615 0.0 0.0 55316 12328 pts/1 S 19:27 0:00 nginx: master process nginx -g daemon off;
root 7544 0.0 0.0 4072 2072 pts/2 S 19:42 0:00 grep --colorauto nginx: master process关闭带有daemon off的这一个
sudo kill -QUIT 3615重新启用nginx
nginx -g daemon off;启动Gradio应用
使用Nginx代理后Gradio应用中不需要使用shareTrue。
demo.launch(shareFalse,server_name0.0.0.0,server_port7860)Gradio应用启动成功后就可以访问https://5awep1xoy9ga5urskya100.deepln.com:30499了。
其它域名
如果自己手下有域名想要通过域名方便地访问自己创建的Gradio应用可以通过在域名解析处通过CNAME将平台提供的外链映射到自己的域名但是需要配置证书可以先浏览一下平台是否提供了配置证书的用户接口如果没有的话可以咨询平台运维人员让他们来配置。