PTT評價

[請益] 使用 Nginx 無法正常顯示頁面

看板Soft_Job標題[請益] 使用 Nginx 無法正常顯示頁面作者
qazsd
(天際線)
時間推噓 X 推:0 噓:4 →:16

請教版上大大,小弟使用Nginx來轉發兩個web service請求,其設定如下

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

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

server {
listen 443 ssl;
server_name for_test.net;
ssl_certificate /etc/nginx/ssl/certs/for_test.crt;
ssl_certificate_key /etc/nginx/ssl/private/for_test.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;
}
}

已知連線到http://192.168.1.150時會成功轉到 https://for_test.net

但是連線到http://192.168.1.150/form時,則會顯示Connection error

http://192.168.1.150/form對應的是使用Streamlit製作的web service

其錯誤似乎是找不到檔案 (HTTP 404,非HTTP 301)

請問是否有大大能夠指點迷津?
感謝

--

※ PTT 留言評論
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 106.1.232.104 (臺灣)
PTT 網址
※ 編輯: qazsd (106.1.232.104 臺灣), 11/28/2023 23:04:46

B098869808811/28 23:15自己作業

layer093011/29 01:45先把網路基本學好…

MoonCode11/29 04:51可以問llm

tsaigi11/29 08:39???

surimodo11/29 10:21看無

taitzyhwan11/29 10:30可以問chatgpt

kurtsgm11/29 11:31https://i.imgur.com/LCX3cF7.png

kurtsgm11/29 11:31我問copilot的 不用謝

godddddd11/29 16:14呃呃 找個可以檢查錯字的

notimenofree11/30 00:55問GPT

srwhite11/30 15:20你打xx.150/form應該會導到for_test.net/form吧

srwhite11/30 15:21看你for_test那有沒有定義form的route

srwhite11/30 15:23或是照你的寫法xx.150:2000可能可以打到 但我是覺得這樣

srwhite11/30 15:23訂有點怪

ssdoz2sk12/01 00:481.先檢查到底有沒有轉址,你弄301,不管有沒有存取到資

ssdoz2sk12/01 00:50源,網址列應該會更新。2. location /form 改成

ssdoz2sk12/01 00:52location /form/ ,不然你 proxy 過去的網址會變成

ssdoz2sk12/01 00:53:4000// 這樣 Streamlit 不是會回你 404 就是 403

ssdoz2sk12/01 00:55此外,你 port 2000 的 URI 是 form or forms 要確定欸~

anecam12/01 10:30for_test.net 的A record 是192.168.1.150?