Rewrite or proxy_pass to internal ip?

Hello,
I want to ask a question about what I to use proxy_pass or rewrite and
how
to use them. Basicly I want to redirect connection to internal server
for
example if user hit: www.mydomain.com/admin/ nginx to redirect all
requests
to http://192.168.1.1/.

I made this with:

 location /admin {
    proxy_pass http://192.168.1.1:80;
    proxy_set_header  X-Real-IP  $remote_addr;
}

But I got Error from http://192.168.1.1 admin does not exists. What I to
do
to redirect all requsts after /admin on web server to internal server
with
admin ?

Regards,
C.

Posted at Nginx Forum:

On Mon, Oct 29, 2012 at 05:40:39AM -0400, hristoc wrote:

Hi there,

 location /admin {
    proxy_pass http://192.168.1.1:80;
    proxy_set_header  X-Real-IP  $remote_addr;
}

But I got Error from http://192.168.1.1 admin does not exists. What I to do
to redirect all requsts after /admin on web server to internal server with
admin ?

http://nginx.org/r/proxy_pass

See the part that starts “A request URI is passed to the server as
follows:”

The short version is:

proxy_pass http://192.168.1.1:80/;

f

Francis D. [email protected]

Francis D. Wrote:

I to do

proxy_pass http://192.168.1.1:80/;

f

Francis D. [email protected]

Thank you,
one step forward but now I receive error 502 bad gateway. Server
mydomain.com have 2 Ethernet. First one with realip that I connect,
second
one with virtual 192.168.1.2 connected to internal network. I don’t want
to
add in my fw redirect rule, so I expect to do it over the web. When I
access
realip or domain name in that directory, I actually to see the web of my
internal server located somewhere in local network.

Posted at Nginx Forum:

On Mon, Oct 29, 2012 at 07:30:00AM -0400, hristoc wrote:

Francis D. Wrote:

Hi there,

proxy_pass http://192.168.1.1:80/;

one step forward but now I receive error 502 bad gateway. Server
mydomain.com have 2 Ethernet. First one with realip that I connect, second
one with virtual 192.168.1.2 connected to internal network. I don’t want to
add in my fw redirect rule, so I expect to do it over the web. When I access
realip or domain name in that directory, I actually to see the web of my
internal server located somewhere in local network.

I’m confused.

Which machine is creating these error messages?

If you start on the public nginx machine, and do

curl -i -0 -H X-Real-IP:\ 10.1.2.3 http://192.168.1.1:80/

what response do you get? What response do you expect?

f

Francis D. [email protected]

On Tue, Oct 30, 2012 at 07:33:14AM -0400, hristoc wrote:

Hi there,

I get real html from internal server with curl and is exact what I expect.

So: when you do “curl -0 -i http://192.168.1.1/” from the nginx server,
you get the same content as when you do “curl -i http://public-ip/admin
from somewhere on the internet?

That suggests that the proxy_pass is working.

For example if I try to access direct js file over the
web like: http://www.mydomain1.com/server1/js/jsquery.js I get error 404
file not found. I think nginx does not forward this request to internal
serve and trying to find the js file on local directory.

How to resolve this issue ?

What is your nginx configuration?

In particular: what “location” blocks do you have?

Module ngx_http_core_module for details. My guess is that you have
something like “location ~ js” as well as “location /admin”, and nginx
chooses that location block for this request.

If that is true, then possibly using “^~” will work for you.

Good luck with it,

f

Francis D. [email protected]

Thank you,
I resolve the problem. My knowledge on nginx is little and I unable to
redirect all js, html to their locations and I did not spend much time
for
that, but your answer give me idea that probably something in my
configuration making nginx to look for these files in different places
ie
some logic in my config is wrong. I added new virtual host name in nginx
and
proxy_pass everything to internal ip and everything is work perfect.
Thank
you for your time.

Here is my configuration if some one looking for some similar. With this
I
redirect web from internel hp iLO web port to external web.

HTTPS server

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name virt.domain1.com;

ssl                  on;
ssl_certificate      /etc/nginx/server.crt;
ssl_certificate_key  /etc/nginx/server.key;
keepalive_timeout    70;
ssl_session_cache    shared:SSL:5m;
ssl_session_timeout  5m;

ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers   on;
location ~ /\.ht {
    deny  all;
}
location / {
    proxy_pass https://192.168.1.200/;
    proxy_set_header Accept-Encoding "";
    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_set_header X-Forwarded-Proto https;
    proxy_redirect off;
}

}

Posted at Nginx Forum:

I get real html from internal server with curl and is exact what I
expect.
Over the nginx I fix the problem with bad gateway, but the problem that
I
now see: nginx does not access remote directories after / for example:

https://www.mydomain.com/server1 I see the html page, but if I organize
my
page with jquery for example and is included from different directory
js/jquery.js I see is not loaded in html ie nginx does not sub
directories,
only top level dir. For example if I try to access direct js file over
the
web like: http://www.mydomain1.com/server1/js/jsquery.js I get error 404
file not found. I think nginx does not forward this request to internal
serve and trying to find the js file on local directory.

How to resolve this issue ?

Posted at Nginx Forum: