# Proxying to ip-camera

**URL:** <https://www.ruby-forum.com/t/proxying-to-ip-camera/244421>\
**Category:** NGINX\
**Created:** [April 7, 2016, 4:02pm UTC](https://www.ruby-forum.com/t/proxying-to-ip-camera/244421 "2016-04-07T16:02:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [April 7, 2016, 4:02pm UTC](https://www.ruby-forum.com/t/proxying-to-ip-camera/244421/1 "2016-04-07T16:02:51Z")

</div>

Hi,

I have the web site and would like to proxying all requests to /ipcam  
location to internal ip-camera.

website [http://site.com](http://site.com)  
ip-cam [http://site.com/ipcam](http://site.com/ipcam)

Below config:

location /ipcam {  
proxy\_pass [http://192.168.20.99:80/](http://192.168.20.99:80/);  
proxy\_redirect off;  
proxy\_set\_header Host $host:$server\_port;  
proxy\_set\_header X-Real-IP $remote\_addr;  
}

All works fine, but ip-cam can not determine UA and therefore I gets  
broken login page and unable to login.

Below the error log from console:

ReferenceError: Browser is not defined  
if(!(Browser.ie7 || Browser.ie8)){

With port redirection by firewall all works fine.

Is anybody can help me. IP-camera - Dahua.

–  
Vitaliy

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [April 7, 2016, 5:44pm UTC](https://www.ruby-forum.com/t/proxying-to-ip-camera/244421/2 "2016-04-07T17:44:30Z")

</div>

> location /ipcam {  
> ReferenceError: Browser is not defined  
> if(!(Browser.ie7 || Browser.ie8)){
> 
> With port redirection by firewall all works fine.
> 
> Is anybody can help me. IP-camera - Dahua.

As I can see the problem is in not proxying static content like JS and  
CSS. Dynamic works fine.

location /ipcam {  
proxy\_pass [http://192.168.20.99:80/](http://192.168.20.99:80/);

```
location ~ \.css {
     proxy_pass http://192.168.20.99:80/
}

```

}

This is not working.

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [April 7, 2016, 10:45pm UTC](https://www.ruby-forum.com/t/proxying-to-ip-camera/244421/3 "2016-04-07T22:45:56Z")

</div>

On Thu, Apr 07, 2016 at 06:44:08PM +0300, wishmaster wrote:

Hi there,

> > I have the web site and would like to proxying all requests to /ipcam location  
> > to internal ip-camera.
> > 
> > website [http://site.com](http://site.com)  
> > ip-cam [http://site.com/ipcam](http://site.com/ipcam)

> > With port redirection by firewall all works fine.

> This is not working.  
> Your first config would probably work if that was the only config in the  
> server{} block. Since it appears that you have some other configuration  
> there, possibly

location ^~ /ipcam/ {  
proxy\_pass [http://192.168.20.99:80/](http://192.168.20.99:80/);  
}

will do what you want. Note: location and proxy\_pass both end in a /,  
and ^~ is used in the location directive.

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#location)**
>
> This directive appeared in version 1.11.8.

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [April 8, 2016, 9:12am UTC](https://www.ruby-forum.com/t/proxying-to-ip-camera/244421/4 "2016-04-08T09:12:44Z")

</div>

On Fri, Apr 08, 2016 at 08:45:48AM +0300, wishmaster wrote:

> > On Thu, Apr 07, 2016 at 06:44:08PM +0300, wishmaster wrote:

Hi there,

> > > > I have the web site and would like to proxying all requests to /ipcam  
> > > > location to internal ip-camera.
> > > > 
> > > > website [http://site.com](http://site.com)  
> > > > ip-cam [http://site.com/ipcam](http://site.com/ipcam)
> > 
> > > > With port redirection by firewall all works fine.

> > location ^~ /ipcam/ {  
> > proxy\_pass [http://192.168.20.99:80/](http://192.168.20.99:80/);  
> > }

> Heh, this server block has another locations as well. E.g. location .css {…}  
> and so on.  
> The second problem is I want to proxying location “/ipcam” to “/” on the  
> ip-camera and I think I must use sub module to overwrite pathes of returned css,js  
> in HTML pages.

You can try that.

Alternatively, if you know the (static) list of urls that the ip-camera  
uses, you could proxy\_pass for each one of those (and make sure that  
your main web service does not use any of the same ones). Or, if the  
content from those urls is constant, you could just copy the content to  
the same urls on your main web server and then not have to proxy\_pass  
the extra ones.

I suspect it will be easier if you can configure the 192.168.20.99  
server  
to believe that its application is installed at /ipcam/ instead of /.

And if that is not possible, it may be easier if you use a new server  
name  
for just the camera – [http://ipcam.site.com](http://ipcam.site.com) which just uses proxy\_pass  
for everything.

In general, I find that it is not trivial to reverse-proxy a web site to  
a different hierarchy level in the url space unless the site was written  
with that in mind.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [April 8, 2016, 9:27am UTC](https://www.ruby-forum.com/t/proxying-to-ip-camera/244421/5 "2016-04-08T09:27:56Z")

</div>

Hi,

— Original message —  
From: “Francis D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: 8 April 2016, 10:12:08

> > > > > With port redirection by firewall all works fine.  
> > > > > Alternatively, if you know the (static) list of urls that the ip-camera  
> > > > > uses, you could proxy\_pass for each one of those (and make sure that  
> > > > > your main web service does not use any of the same ones). Or, if the  
> > > > > content from those urls is constant, you could just copy the content to  
> > > > > the same urls on your main web server and then not have to proxy\_pass  
> > > > > the extra ones.

Yes, I have thought about this. This will work.

> I suspect it will be easier if you can configure the 192.168.20.99 server  
> to believe that its application is installed at /ipcam/ instead of /.
> 
> And if that is not possible, it may be easier if you use a new server name  
> for just the camera – [http://ipcam.site.com](http://ipcam.site.com) which just uses proxy\_pass  
> for everything.

I think this is the esiest way. Thanks.

> In general, I find that it is not trivial to reverse-proxy a web site to  
> a different hierarchy level in the url space unless the site was written  
> with that in mind.

Yes, you truth.

> Good luck with it,
> 
> ## f
> 
> Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

Vitaliy

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [April 8, 2016, 7:46am UTC](https://www.ruby-forum.com/t/proxying-to-ip-camera/244421/6 "2016-04-08T07:46:16Z")

</div>

Hi, Francis.

> > This is not working.  
> > and ^~ is used in the location directive.  
> > Heh, this server block has another locations as well. E.g. location  
> > .css {…} and so on.  
> > The second problem is I want to proxying location “/ipcam” to “/” on the  
> > ip-camera and I think I must use sub module to overwrite pathes of  
> > returned css,js in HTML pages.

–  
Vitaliy
