作者qazsd (天際線)
標題[請益] 使用Nginx顯示找不到檔案
時間2023-11-28 22:25:21
請教版上大大,小弟使用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)
請問是否有大大能夠指點迷津?
感謝
--
※ 發信站: 批踢踢實業坊(pttsite.org.tw), 來自: 106.1.232.104 (臺灣)
※ 文章網址: https://pttsite.org.tw/Soft_Job/M.1701181526.A.5AE
噓 B0988698088: 自己作業 11/28 23:15
→ layer0930: 先把網路基本學好… 11/29 01:45
噓 MoonCode: 可以問llm 11/29 04:51
噓 tsaigi: ??? 11/29 08:39
→ surimodo: 看無 11/29 10:21
推 AKNY: 那個包養網人最多XD 11/29 10:21 → taitzyhwan: 可以問chatgpt 11/29 10:30
→ kurtsgm: 我問copilot的 不用謝 11/29 11:31
噓 godddddd: 呃呃 找個可以檢查錯字的 11/29 16:14
→ notimenofree: 問GPT 11/30 00:55
推 mysister: 我妹上包養網被我發現= = 11/30 00:55 → srwhite: 你打xx.150/form應該會導到for_test.net/form吧 11/30 15:20
→ srwhite: 看你for_test那有沒有定義form的route 11/30 15:21
→ srwhite: 或是照你的寫法xx.150:2000可能可以打到 但我是覺得這樣 11/30 15:23
→ srwhite: 訂有點怪 11/30 15:23
→ ssdoz2sk: 1.先檢查到底有沒有轉址,你弄301,不管有沒有存取到資 12/01 00:48
推 cir72: 隔壁桌的人竟然在討論包養... 12/01 00:48 → ssdoz2sk: 源,網址列應該會更新。2. location /form 改成 12/01 00:50
→ ssdoz2sk: location /form/ ,不然你 proxy 過去的網址會變成 12/01 00:52
→ ssdoz2sk: :4000// 這樣 Streamlit 不是會回你 404 就是 403 12/01 00:53
→ ssdoz2sk: 此外,你 port 2000 的 URI 是 form or forms 要確定欸~ 12/01 00:55
→ anecam: for_test.net 的A record 是192.168.1.150? 12/01 10:30
推 ATrain: 樓上是不是被包養 12/01 10:30 → qazsd: 回樓上,是私有網域供連線用的網址,非public IP 12/06 00:20
→ anecam: 80 server 改成location ~ /form {return 301 URL; }??? 12/08 21:24
→ anecam: 後來只細看你是用http連不是https 12/08 21:24