Nginx - Streamlit 프록시 설정 방법

2024. 8. 30. 09:55·💻 Study/웹
728x90

Streamlit과 Nginx 각각에서의 설정을 해줘야 하다.

 

Streamlit

아무것도 설정할 필요 없다. 기본값으로 8501번 포트에서 streamlit app이 실행된다.

만약 port 등을 설정하고 싶다면, 프로젝트 디렉토리 내 .streamlit/config.toml 에서 설정할 수 있다.

# 예시
[server]
port=8000

 

Nginx

/etc/nginx/nginx.conf 에서 nginx가 지켜볼 port와 이 port로 들어오는 요청을 전달할 주소, 즉, streamlit이 실행되고 있는 주소를 연결해줘야 한다.

 

  1. http.server 설정을 아래와 같이 해준다.
    • proxy_pass에는 streamlit app이 실행되고 있는 주소를 넣어줘야 한다.
      • 따로 설정해준 게 없다면, http://localhost:8501일 것이다.
    • /_stcore/stream 에 대해 설정해줘야 한다.
      • 만약, 설정하지 않았다면, /_stcore/stream 의 웹소켓 연결이 계속해서 실패하게 된다.
        이 경우, /_stcore/stream, /_stcore/health, /_stcore/host-config 로의 요청이 무한히 발생한다.
# nginx.conf
# ...

http {
    # Server Configs
    server {
        listen 80;
        listen [::]:80;

        charset utf-8;

        server_name domain.com; # or public ip address

        location / {
            proxy_pass http://localhost:8501;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            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;
        }

        location /_stcore/stream {
            proxy_pass http://localhost:8501/_stcore/stream;
            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;
        }
    }

    # ... Additional Settings
}

 

  1. nginx.conf 파일을 수정했다면, 실행에 이상이 없는 지 검사해준다.
sudo nginx -t

>> 출력에 successful이 나타나면, 문제가 없는 것이다.

 

 

  1. nginx 서버를 재시작해준다.
sudo service nginx restart
728x90
저작자표시

'💻 Study > 웹' 카테고리의 다른 글

Nginx - Flask 프록시 방법 (Feat. Gunicorn)  (0) 2024.09.24
[Node.js] MySQL2 모듈 장기간 연결 문제 해결  (0) 2024.07.02
[React] map() vs forEach(): Array.prototype.map() expects a return value from arrow function.  (0) 2024.06.27
[MySQL] java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver | MySQL JDBC Driver Not Found  (0) 2022.07.18
[netlify] Page Not Found Error (React Router)  (1) 2022.01.03
'💻 Study/웹' 카테고리의 다른 글
  • Nginx - Flask 프록시 방법 (Feat. Gunicorn)
  • [Node.js] MySQL2 모듈 장기간 연결 문제 해결
  • [React] map() vs forEach(): Array.prototype.map() expects a return value from arrow function.
  • [MySQL] java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver | MySQL JDBC Driver Not Found
soyang.
soyang.
코딩 및 개발 일지를 기록합니다.
  • soyang.
    소소한 코딩일지
    soyang.
  • 전체
    오늘
    어제
  • 링크

    • Github 🐾
    • 포트폴리오 📓 (리뉴얼중)
    • LinkedIn 👩🏻‍💼
  • 공지사항

    • 소소한 코딩일지
  • 블로그 메뉴

    • 방명록
    • 분류 전체보기 (181)
      • 🚩 목표 & 회고 (9)
      • 📓 Papers (10)
      • 🧇 Algorithm (44)
        • 이론 (1)
        • LeetCode (2)
        • 프로그래머스 (30)
        • 백준 (11)
      • 💻 Study (47)
        • 🤖 AI 인공지능 (3)
        • Python 파이썬 (3)
        • Docker 도커 (4)
        • 웹 (20)
        • 안드로이드 (2)
        • JAVA 자바 (1)
        • Firebase (3)
        • Linux 리눅스 (10)
      • 🍪 Projects (2)
      • 🎒 학교 (44)
        • 대학원 도비 (2)
        • 21 동계 모각코: 슈붕팥붕 (13)
        • 21 하계 모각코: 와팬호 (13)
        • 20 동계 모각코: 와팬호 (13)
      • 활동들 (16)
        • 인프런 대학생 LEAF 2기 (9)
        • 2021 Silicon Valley Online .. (7)
  • 태그

    모각코
    인프런대학생Leaf
    Algorithm
    Ai
    알고리즘스터디
    programmers
    Linux
    Artificial Intelligence
    백준
    코딩테스트
    프로그래머스
    노마드코더
    리액트
    error
    목표
    Gentoo
    공부
    알고리즘
    React
    Python
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
soyang.
Nginx - Streamlit 프록시 설정 방법
상단으로

티스토리툴바