Welcome! Log In Create A New Profile

Advanced

Proxy Subdirectory to Local URL

Posted by amy_half 
Proxy Subdirectory to Local URL
November 15, 2010 03:30PM
Hi, I'm trying to setup my Nginx to proxy a subdirectory to an internal IP on the network.

[code]
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

location /linksys {
proxy_pass http://192.168.0.1/;
}
[/code]

The page at [b]http://192.168.0.1[/b] seems to do a POST to this relative URL: [b]/prelogin.html[/b] where the top [b]location[/b] directive picks it up and boom, we're done.

I've tried various permutations of the [code]proxy_redirect[/code] and even messing around with [code]rewrite[/code] but nothing seems to work.

I know it's something small and stupid that I'm missing. Help and thanks in advance!
Re: Proxy Subdirectory to Local URL
November 15, 2010 04:01PM
This doesn't work, either:

[code]
location /linksys {
proxy_pass http://192.168.0.1/;
proxy_redirect http://<my server hostname here> http://192.168.0.1;
}
[/code]
Re: Proxy Subdirectory to Local URL
November 15, 2010 04:02PM
If I put

[code]
rewrite ^(.*) http://<my server host url here>/linksys/$1 break;
[/code]

attempting to send it to the above location directive, it goes into an endless loop.
Re: Proxy Subdirectory to Local URL
November 15, 2010 04:05PM
If it's helpful at all, if I do a

[code]
curl -v -u <my user>:<my pass> http://192.168.0.1
[/code]

The headers look like this:

[code]
* About to connect() to 192.168.0.1 port 80 (#0)
* Trying 192.168.0.1... connected
* Connected to 192.168.0.1 (192.168.0.1) port 80 (#0)
* Server auth using Basic with user '<my user>'
> GET / HTTP/1.1
> Authorization: Basic <hashed authentication thingee>
> User-Agent: curl/7.21.0 (i386-redhat-linux-gnu) libcurl/7.21.0 NSS/3.12.7.0 zlib/1.2.5 libidn/1.18 libssh2/1.2.4
> Host: 192.168.0.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Pragma: no-cache
< Content-Type: text/html
<
<html>
<head>
...
[/code]
Re: Proxy Subdirectory to Local URL
December 01, 2010 06:31PM
I think that you are trying to do what I am currently doing. The community isn't very strong here for some reason, so I was able to figure out part of what I wanted to do after many long painful days of trial and error and reading.

Try this as it works for me:

[code]
location /linksys/ {
proxy_pass http://192.168.0.1/;
index index.html;
}
[/code]

I think that in order to make it work for [code]
location / {
[/code] you will have to make your web servers document root this folder: /usr/share/nginx/html
Then you could do this:
[code]
location / {
proxy_pass http://127.0.01;
index index.html index.htm;
}
[/code]

Hope this helps you out.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 152
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready