location - Nginx Passing to Servers Based on URI -
i have been setting nginx on router, , creating subdomains (with cnames) access various components within network. has been easy, until have come cameras proving problem.
they basic ip cameras , date had opened each 1 on different port. have basic authentication, , once has been entered presented live view.
like other components have set far (and work) started configuring one:
server { listen 80; server_name cam.example.co.uk; location / { proxy_pass http://192.168.1.101:2001; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } }
hitting cam.example.co.uk
either lan or wan gives me username , password prompt , live view loads.
since there 9 cameras, thought idea use /1
, /2
, /3
etc. @ end direct me each 1 rather can creating subdomains.
server { listen 80; server_name cam.example.co.uk; location /1/ { proxy_pass http://192.168.1.101:2001; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } location /2/ { proxy_pass http://192.168.1.102:2002; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } }
with got 404 not found errors, , messages in logs such as:
"/usr/html/new/index.htm" failed (2: no such file or directory)
some googling later found out may need specify uri in proxy_pass line, changed them like:
proxy_pass http://192.168.1.102:2002/new/index.htm;
this results in username , password prompt, when credentials entered, left blank screen. worked fine when location /
no idea why nothing showing now.
i have feeling putting uri in somewhere, have no idea where/why or it.
edit
been googling , trying various things:
location /1 { resolver 127.0.0.1; set $backend "http://192.168.1.101:2001/new/index.htm"; proxy_pass $backend; proxy_buffering on; proxy_redirect http://192.168.1.101:2001/new/index.htm http://cam.example.co.uk/1; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; }
then going in browser cams.example.co.uk/1
brings username , password prompt, displays blank page. looking @ chrome developer tools can see unexpected token errors, , looks isn't loading .js files properly.
if proxy_pass directive specified uri, when request passed server, part of normalized request uri matching location replaced uri specified in directive.
try this:
server { listen 80; server_name cam.example.co.uk; location /1/ { proxy_pass http://192.168.1.101:2001/; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_redirect http://192.168.1.101:2001/ http://cam.example.co.uk/1/; } location /2/ { proxy_pass http://192.168.1.102:2002/; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_redirect http://192.168.1.101:2002/ http://cam.example.co.uk/2/; } }
source: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
Comments
Post a Comment