[请益] 使用 Nginx 无法正常显示页面

楼主: qazsd ( )   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)
请问是否有大大能够指点迷津?
感谢
作者: B0988698088 (废文少女小円♥)   2023-11-28 23:15:00
自己作业
作者: layer0930 (皇室御渍梨子酱)   2023-11-29 01:45:00
先把网络基本学好…
作者: MoonCode (MoonCode)   2023-11-29 04:51:00
可以问llm
作者: tsaigi (菜鸡)   2023-11-29 08:39:00
???
作者: surimodo (好吃棉花糖)   2023-11-29 10:21:00
看无
作者: taitzyhwan (资本主义)   2023-11-29 10:30:00
可以问chatgpt
作者: kurtsgm   2023-11-29 11:31:00
https://i.imgur.com/LCX3cF7.png我问copilot的 不用谢
作者: godddddd (howudoing)   2023-11-29 16:14:00
呃呃 找个可以检查错字的
作者: notimenofree (逼逼逼逼逼)   2023-11-30 00:55:00
问GPT
作者: srwhite (鲁蛇阿白)   2023-11-30 15:20:00
你打xx.150/form应该会导到for_test.net/form吧看你for_test那有没有定义form的route或是照你的写法xx.150:2000可能可以打到 但我是觉得这样订有点怪
作者: ssdoz2sk (眷恋着提拉米苏的风采~)   2023-12-01 00:48:00
1.先检查到底有没有转址,你弄301,不管有没有存取到资源,网址列应该会更新。2. location /form 改成location /form/ ,不然你 proxy 过去的网址会变成:4000// 这样 Streamlit 不是会回你 404 就是 403此外,你 port 2000 的 URI 是 form or forms 要确定欸~
作者: anecam (诚意大将军)   2023-12-01 10:30:00
for_test.net 的A record 是192.168.1.150?
楼主: qazsd ( )   2023-12-06 00:20:00
回楼上,是私有网域供连线用的网址,非public IP
作者: anecam (诚意大将军)   2023-12-08 21:24:00
80 server 改成location ~ /form {return 301 URL; }???后来只细看你是用http连不是https

Links booklink

Contact Us: admin [ a t ] ucptt.com