AxiosError: Request failed with status code 400 : I'm using nginx in a docker environment, but I get an error

please tell me!

  1. I am running the app locally.
  2. The error is displayed in the browser started with streamlit, and there is no error in the standard output.
  3. I am running in the following environment.
    I have an ubuntu22.04 instance set up on AWS EC2.
    In this, a Docker container is started and streamlit is running based on the following settings.
    What happened was a simple file upload function, and when the file was uploaded, an error was displayed on the screen.
# specify base image
FROM ubuntu:22.04

# Set environment variables to avoid questions when building the front end
ENV DEBIAN_FRONTEND=noninteractive

# Install Python 3.10, sqlite3 command line tools, and required packages
# install vim and git
RUN apt-get update && apt-get install -y \
     python3.10\
     python3-pip\
     python3.10-venv\
     libsqlite3-dev\
     sqlite3 \
     vim\
     git\
     && rm -rf /var/lib/apt/lists/*

# set working directory
WORKDIR/apps

# Install required Python libraries from requirements.txt
COPY requirements.txt /apps/requirements.txt
RUN python3.10 -m pip install -r requirements.txt

# Copy the application code to the container
COPY . /apps

# Open Streamlit default port
EXPOSE 8501

# Command to start the Streamlit app in auto-reload mode
CMD ["streamlit", "run", "run.py", "--server.runOnSave=true", "--server.enableCORS=false", "--server.enableXsrfProtection=false", "--client .toolbarMode=minimal", "--server.maxUploadSize=500"]
# specify base image
FROM nginx:alpine

# Copy Nginx configuration file to container
COPY nginx.conf /etc/nginx/nginx.conf

# Open Nginx default port
EXPOSE 8010
events {
     worker_connections 1024;
}

http {
     upstream streamlit {
         ip_hash; # Provide same IP
         least_conn; # use least connections algorithm
         server streamlit-app1:8501;
         server streamlit-app2:8501;
         server streamlit-app3:8501;
     }

     server {
         listen 8010;

         location / {
             proxy_pass http://streamlit;
             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;
             # WebSocket support
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection "upgrade";
             client_max_body_size 500M; # Increase file size limit
         }

         location /upload {
             proxy_pass http://streamlit;
             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;
             client_max_body_size 500M; # Increase file size limit
         }

         location /stream {
             proxy_pass http://streamlit;
             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_read_timeout 86400;
             proxy_send_timeout 86400;
             proxy_connect_timeout 86400;
             send_timeout 86400;
         }
     }
}
         uploaded_file = st.sidebar.file_uploader("Please upload training data", type=['csv'])

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.