I have an Ubuntu Server that I use as a web server. Everything works great, I have multiple sites set up. My router allows only one device to own the public IP which is my Ubuntu Server. I set up a RaspberryPi with a Camera and Motion. Again, everything works great - I can access the Cam via a browser (IP:8081).
I want to run a website from my Ubuntu and display a live stream from the raspberry. This works great with <img src="IP:8081?action=stream />
. However, since the raspberry is internal IP only, I can't see the stream when I'm outside my network.
What do I need to do to have my Ubuntu accessing the raspberry and feedback the stream?
The app is based on codeigniter by the way, motion is set up to work outside locahost as well.
So you have a server that straddles two networks (WAN and LAN) and you want to expose something from the LAN on the WAN, as part of other content the server hosts.
The easiest way is to tell your HTTP server to proxy the connection. Most servers can do this but I'd do it with Nginx over anything else because it's the best (fastest, smallest, etc, etc). You would use a rule like this:
location /webcam/ {
proxy_pass http://internal_webcam_IP:8081/?action=stream;
}
For Apache, the same holds true... You just create a quick reverse proxy:
ProxyRequests off
ProxyPass /webcam http://internal_webcam_IP:8081/?action=stream
And then change the HTML image location to:
<img src="/webcam/" />
The networking side of this should be fairly simple but the image hosting on the webcam might not work in an image tag (some use MJPEG, some use javascript) so you might need to embed a page via an iframe, or write some new javascript to update the image (cleaner than the iframe but more work). If you do this, you might need to open up the proxy so it isn't just mirroring the /?action=stream
URL.
That complicates things. We're talking about embedded hardware here: famously under-updated and —on the whole— infamously easy to hack. If you do need to open the proxy up to a wider selection of URLs you'll probably also want to add a load of explicit URLs to be blocked to stop external people gaining too much access to your internal network.
The other direction is to use PHP and CodeIgniter to proxy whatever you need.... However a general webdev rule of thumb is that if you can avoid it, don't tie up your server side language handling menial tasks. This is something you can offload to the webserver (or even the networking stack — which I'm not going into because it offers no security at all).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments