billwill56
Posts: 2
Joined: Wed Sep 17, 2014 10:57 pm

MJPG-Streamer with Apache 2 not working over internet

Wed Sep 17, 2014 11:20 pm

I have run in to a strange issue. I am using mjpg-streamer and have embedded the stream into a site I am hosting through Apache2. When I access the site locally, everything works as it should. When I attempt to access the page through the internet it will not load properly. I have forwarded and connected through several different ports from outside my network. I have also configured Apache to host on ports other than 80 but with no success from outside. If I access it from the internet, the buttons and other forms will show up on the page. The frame for the mjpg stream also appears but only the icon indicating that it cannot load appears inside.

Right now mjpg-streamer is broadcasting through 8080 again and is embedded in my Apache hosted site using the following.

Code: Select all

<img alt="" src="http://raspi:8080/?action=stream" width="1280" height="960" />
I have tried several different frame rates as well as sizes and the problem is the same. I can access it locally but not elsewhere.

Any help or even wild guesses would be much appreciated. Thank you.

ethanol100
Posts: 641
Joined: Wed Oct 02, 2013 12:28 pm

Re: MJPG-Streamer with Apache 2 not working over internet

Thu Sep 18, 2014 9:08 am

The browser tries to connect directly to "http://raspi:8080/?action=stream" and loads that image which can not be found when outside of your local network.

If you use port forwarding for raspi:8080 you could reach the stream at http://"external ip or dynamic dns name":8080/?action=stream .

Sorry have no idea how to solve this, so I can just provide some guesses:

use javascript to generate the href? http://stackoverflow.com/questions/6016 ... -hyperlink

use apache as reverse proxy to be able to access the stream over the same apache server. Similar to i.e. http://blog.paulregan.co.uk/2013/02/fos ... proxy.html

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MJPG-Streamer with Apache 2 not working over internet

Thu Sep 18, 2014 9:34 am

What you will need to do is add this to your Apache2 config (using mod_proxy):

Code: Select all

    ProxyPass /RPi http://raspi:8080/
    ProxyPassReverse /RPi http://raspi:8080/
you may need to install and activate mod_proxy for that.

Your HTML then needs to change to

Code: Select all

<img alt="words for the visually impaired folks to describe the image" src="/RPi?action=stream" width="1280" height="960" />
using a relative URL that will be re-directed to your RPi when Apache2 receives the GET request.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

billwill56
Posts: 2
Joined: Wed Sep 17, 2014 10:57 pm

Re: MJPG-Streamer with Apache 2 not working over internet

Thu Sep 18, 2014 11:15 pm

Thank you ethanol and Dougie for your suggestions and clarification on the reason it would not load when not local. I did get this working using a php proxy. I used an example from another site which I will paste below and reference in a link.

Code: Select all


/*
usage on webpage:
<img src="stream.php">
*/ 

php page:

<?php
$server = "localhost"; // camera server address
$port = 8443; // camera server port
$url = "/?action=stream"; // image url on server
set_time_limit(0);  
$fp = fsockopen($server, $port, $errno, $errstr, 30); 
if (!$fp) { 
        echo "$errstr ($errno)<br>\n";   // error handling
} else { 
        $urlstring = "GET ".$url." HTTP/1.0\r\n\r\n"; 
        fputs ($fp, $urlstring); 
        while ($str = trim(fgets($fp, 4096))) 
        header($str); 
        fpassthru($fp); 
        fclose($fp); 
} 
?>
I came across this here:
http://www.plugcomputer.org/plugforum/i ... pic=6231.0

Also for anyone not already aware, do not use the http:// in front of the server address.

Thanks again for the help.

Maxem
Posts: 1
Joined: Wed Jan 07, 2015 8:25 pm

Re: MJPG-Streamer with Apache 2 not working over internet

Tue Jan 13, 2015 1:15 pm

I have a nearly simliar problem.
Mjpeg-stream works fine and stream at port 8080.
The mod_proxy ist installed and worked for "motion" from early times. So i reconfigured it as below:

Code: Select all

ProxyRequests Off
<Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
</Proxy>
ProxyVia On
ProxyPass /webcam http://192.168.1.xxx:8080
# xxx=IP from raspi
-
If i type 192.168.1.xxx/webcam i see a page with the "broken picture"-icon - the stream does not start.
if i type 192.168.1.xxx:8080 i can see the "broken picture"-icon for 1 second and then i can see the streaming video.
the sourcecode of both pages is the same!
It makes no differenz what browser i use, or if i try to reach it inside my LAN or from outside - all the same effect.

Whats running wrong with Apache2 here, please?

Szabi
Posts: 2
Joined: Tue Feb 02, 2016 5:07 pm

Re: MJPG-Streamer with Apache 2 not working over internet

Tue Feb 02, 2016 5:21 pm

If both servers run on the same raspberry you need to enable port forwarding on port 8080 (mjpg-streamer).
After that replace the local address to external address e.g <img src='http://4x.12x.4x.3x:8080/?action=stream' />

Return to “Camera board”