Rewriting and proxy problem

H folks!

I am completeley newbie to nginx

I have the following config

    # Forward request to /demo to tomcat.  This is for
     # the BigBlueButton api demos.
   location /demo {
       rewrite ^ /upvc;
       proxy_pass         http://127.0.0.1:8080;
       proxy_redirect     default;
       proxy_set_header   X-Forwarded-For 

$proxy_add_x_forwarded_for;

    # Allow 30M uploaded presentation document.
       client_max_body_size       30m;
       client_body_buffer_size    128k;

       proxy_connect_timeout      90;
       proxy_send_timeout         90;
       proxy_read_timeout         90;

       proxy_buffer_size          4k;
       proxy_buffers              4 32k;
       proxy_busy_buffers_size    64k;
       proxy_temp_file_write_size 64k;

       include    fastcgi_params;
   }

location /upvc {
alias /var/lib/tomcat6/webapps/demo;
index demo3.jsp;
expires 1m;
}

Rewrite is working but nginx is not. proxying to tomcat, because of
that
returns the jsp file as a plain text file.

Please could you help me?

Thanks in advance!

Let’s start by a huge RTFM?
http://nginx.org/en/docs/

This ML is no customer service for lazy people, I guess.
You may up for services to make other people do your job:

Best regards,

B. R.

On Fri, May 24, 2013 at 02:39:58PM -0300, Sergio B. wrote:

Hi there,

I am completeley newbie to nginx

Welcome.

The nginx config follows its own logic, which may not match your
previous
experiences. When you understand that, you’ll have a much better chance
of knowing the configuration you are looking for.

One important feature is that one request is handled in one
location. Another is that one http request does not necessarily
correspond
to one nginx request.

In this case…

you make the request for /demoX, and the best-match location is
“location
/demo”, and so that is the one that is used.

   location /demo {
       rewrite ^ /upvc;

Once that happens, you are using the new internal-to-nginx request
“/upvc”, so a new choice for best-match location happens, and the rest
of this location{} block is not relevant.

       proxy_pass         http://127.0.0.1:8080;
       include    fastcgi_params;

Aside: the fastcgi_params file will typically have content relevant for
when fastcgi_pass is used, not for when proxy_pass is used.

So, the http request for /demoX leads to the nginx request for /upvc,
which matches this location:

location /upvc {
alias /var/lib/tomcat6/webapps/demo;
index demo3.jsp;
expires 1m;

And here, you say “serve it from the filesystem”, so that’s what it
does.

(I suspect that you actually get a http redirect to /upvc/, which then
returns the content of /var/lib/tomcat6/webapps/demo/demo3.jsp. Using
“curl” as the browser tends to make clear what is happening.)

}

Rewrite is working but nginx is not. proxying to tomcat, because of that
returns the jsp file as a plain text file.

Please could you help me?

The hardest part of nginx config that I find, it working out what
exactly
you want to have happen for each request.

From the above sample config, I’m not sure what it is that you want.

Perhaps putting the proxy_pass in the “location /upvc” block will work?
Or
perhaps removing the rewrite?

If you can describe what behaviour you want, then possibly the nginx
config to achieve it will become clear.

f

Francis D. [email protected]

2013/5/27 Sergio B. [email protected]

to one nginx request.
“/upvc”, so a new choice for best-match location happens, and the rest
which matches this location:
“curl” as the browser tends to make clear what is happening.)
you want to have happen for each request.



Anyway it’s obvious that results in “not found” tomcat upvc directory
does
not exist,. Shame on me :cry:

2013/5/25 Francis D. [email protected]

of knowing the configuration you are looking for.

Yup, I’ve began to read the documentation :slight_smile:

       rewrite ^ /upvc;

when fastcgi_pass is used, not for when proxy_pass is used.

(I suspect that you actually get a http redirect to /upvc/, which then
returns the content of /var/lib/tomcat6/webapps/demo/demo3.jsp. Using
“curl” as the browser tends to make clear what is happening.)

}

Rewrite is working but nginx is not. proxying to tomcat, because of that
returns the jsp file as a plain text file.

Please could you help me?

The hardest part of nginx config that I find, it working out what
exactly

you want to have happen for each request.

From the above sample config, I’m not sure what it is that you want.

Perhaps putting the proxy_pass in the “location /upvc” block will work? Or
perhaps removing the rewrite?

I did it, and tried using curl, tomcat complains that it cannot find
/upvc.

If you can describe what behaviour you want, then possibly the nginx
config to achieve it will become clear.

I’d want that when you type http://example.com/upvc proxies the
/var/lib/tomcat6/webapps/demo/
demo3.jsp file to tomcat

Thanks for your nice explanation

On Mon, May 27, 2013 at 11:31:37AM -0300, Sergio B. wrote:

Hi there,

I’d want that when you type http://example.com/upvc proxies the
/var/lib/tomcat6/webapps/demo/
demo3.jsp file to tomcat

Just for clarity, “proxy_pass” proxies to a url, not to a file. So you
probably want it to proxy to http://127.0.0.1:8080/demo/demo3.jsp

If I’ve got the mapping of url/filename wrong, adjust it as necessary.

You haven’t said what any other requests to nginx should do, so I will
show an example for only exactly what you said.

There is not an obvious mapping from /upvc to /demo/demo3.jsp, so I
won’t include any kind of generic replacement here.

You will find very useful information on all of this at
http://nginx.org/r/proxy_pass

So, in the appropriate server block, you want something like:

location = /upvc {
rewrite ^ /demo/demo3.jsp break;
proxy_pass http://127.0.0.1:8080;
}

This will handle requests for /upvc and /upvc?something. The
documentation
should explain why it works.

All of the other directives can be added back, when you know why they
are needed here.

Cheers,

f

Francis D. [email protected]