概要:
最近遇到开发使用streamlit开发的一个服务,需要通过nginx代理,发现通过nginx代理后,业务访问有问题。提示如下错误:
解决办法:
nginx配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 8501;
server_name localhost;
location / {
proxy_pass http://192.168.100.144:8501/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
location /_stcore/stream {
proxy_pass http://192.168.100.144:8501;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
streamlit配置文件修改
root@minipc:/opt/streamlit# cat ~/.streamlit/config.toml
[server]
enableCORS = false
#测试代码
root@minipc:/opt/streamlit# cat streamlit.py
import streamlit as st
x = st.slider("Select a value")
st.write(x, "squared is", x * x)
#启动服务
root@minipc:/opt/streamlit# streamlit run streamlit.py
参考链接:
https://discuss.streamlit.io/t/streamlit-docker-nginx-ssl-https/2195
https://discuss.streamlit.io/t/how-to-use-streamlit-with-nginx/378
https://docs.streamlit.io/library/advanced-features/configuration
Comments | NOTHING