简体   繁体   English

从外部访问 Raspberry PI Django 服务器

[英]Access Raspberry PI Django server from outside

I have a Raspberry PI with Django installed.我有一个安装了 Django 的 Raspberry PI。 The PI has a static IP on my network ( 192.168.1.100 ) and the web server is on port 8008. PI 在我的网络 ( 192.168.1.100 ) 上有一个静态 IP,而 Web 服务器在端口 8008 上。

I can access my website from the local network at the address http://192.168.1.100:8008/ as one would expect.我可以从地址http://192.168.1.100:8008/的本地网络访问我的网站,正如人们所期望的那样。

On my routeur, with WAN address (say) 1.1.1.1 , I forwarded port 8008 to the IP 192.168.1.100 and therefore I should expect http://1.1.1.1:8008/ to show me my website.在我的路由器上,WAN 地址(例如) 1.1.1.1 ,我将端口 8008 转发到 IP 192.168.1.100 ,因此我应该期待http://1.1.1.1:8008/向我展示我的网站。 However it doesn't.然而事实并非如此。

When I redirect port 8008 to another PC where I have an Apache server on port 8008, it works fine from the outside.当我将端口 8008 重定向到另一台我在端口 8008 上有 Apache 服务器的 PC 时,它从外部工作正常。 I only have the problem on this device.我只有这个设备有问题。

The Django app itself does not seem to reject connections from the outside (I installed it on my Mac on a different network and I could access it from the outside). Django 应用程序本身似乎不会拒绝来自外部的连接(我将它安装在不同网络的 Mac 上,我可以从外部访问它)。

So I don't know what I am missing... is there some parameter on the PI that could block requests?所以我不知道我错过了什么...... PI 上是否有一些参数可以阻止请求?

Here's a quick solution.这是一个快速解决方案。 You can try services like localtunnel or ngrok to port forward.你可以尝试像服务localtunnelngrok到端口转发。

Or if you want a more rigid solution you could forward ports from your router.或者,如果您想要更严格的解决方案,您可以从路由器转发端口。

Or at last you could use a reverse proxy from cloud or a VPN network.或者最后您可以使用来自云或 VPN 网络的反向代理。

Choose whatever suits your situation the best.选择最适合您情况的方式。

在 settings.py 中,尝试将您的 WAN 地址添加到允许的主机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM