Somehow the content cannot be display while using Nginx

19 Views Asked by At

My Nginx conf file for 2 web services is as follows:

  server {
     listen 80;
     listen 1000;
     server_name 192.168.1.150;
     return 301 https://for_stackoverflow.net$request_uri;
  }

  server {
  listen 2000;
  server_name 192.168.1.150;
  return 301 https://for_stackoverflow.net/forms$request_uri;
  }

  server {
     listen 443 ssl;
     server_name for_stackoverflow.net;
     ssl_certificate     /etc/nginx/ssl/certs/for_stackoverflow.crt;
     ssl_certificate_key /etc/nginx/ssl/private/for_stackoverflow.key;
     ssl_session_timeout 5m;
     ssl_session_cache shared:SSL:50m;
     ssl_session_tickets off;
     ssl_protocols TLSv1.2 TLSv1.3;
     ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';
     ssl_prefer_server_ciphers   on;
     add_header Strict-Transport-Security "max-age=31536000" always;

     ### A PyWebIO web service ###
     location / {
        proxy_pass http://127.0.0.1:3000/; 
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Photo $scheme;
        proxy_set_header HOST $host;
        proxy_set_header X-Real-IP $remote_addr;
     }
     
     ### A Streamlit web service ###
     location /form {
        proxy_pass http://127.0.0.1:4000/;
        alias /home/streamlit_app/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Photo $scheme;
        proxy_set_header HOST $host;
        proxy_set_header X-Real-IP $remote_addr;
     }
  }

Whether I visit http://192.168.1.150 or https://192.168.1.150, the page will be directed to https://for_stackoverflow.net which this behavior is correct.

However, when I visit http://192.168.1.150/form, the Streamlit website cannot show the page correctly and prompts a warning message "Connection error 0", it seems that the files cannot be found.

The web service seems to use Websocket. How can I resolve this issue? Thank you.

0

There are 0 best solutions below