Spaces in URI

On Fri, Jun 11, 2010 at 02:54:35AM -0400, Peter Portante wrote:

switched our environment to front those Apache servers with a pair of Nginx
or configuration parameter in Nginx that would make it more forgiving of

Thanks for any help or pointers you can offer.

Try the attached patch against 0.8.40.

Hi Igor,

This is working great. Thank you!

Should we be prepared to maintain this as a patch on the 0.8 stream, or
would some variation of this fix be folded into 0.8 (via some config
setting
or as the new behavior)?

And while we are at it, how stable is 0.8? I thought I had seen some
discussion of 0.8 being marked “stable” soon. Just curious.

Thanks,

-peter

Great. Thanks Igor, we are using it. :slight_smile: -peter

On Fri, Jun 11, 2010 at 04:07:10PM -0400, Peter Portante wrote:

Hi Igor,

This is working great. Thank you!

Should we be prepared to maintain this as a patch on the 0.8 stream, or
would some variation of this fix be folded into 0.8 (via some config setting
or as the new behavior)?

And while we are at it, how stable is 0.8? I thought I had seen some
discussion of 0.8 being marked “stable” soon. Just curious.

Here is a new patch that encodes these spaces as %20 while talking
to a proxied backend. I’m going to commit the patch in next 0.8.41.
0.8 is stable, use it.

Hello folks,

I’m tried both nginx 0.8.46 and 0.8.52 to reverse proxy a URI with a
whitespace, but I’m having no luck. Any URI without a space loads just
fine, but one that contains a white space results in a “Bad Request -
HTTP Error 400. The request is badly formed.” I verified that the
patch reference above was in 0.8.46. [The %20 substitution was missing
from the proxy module so I added it but it didn’t help.]

Are you folks about to reverse proxy a white space URI like
http://forum.nginx.org/siteX/storage/Nice Images/test-image.jpg”
That’s not a valid URI. I just wanted to give an example that shows the
type of white space that is in my URI.

thanks,
Chris

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,134984#msg-134984

Reposting to fix the grammar errors!

Hello folks,

I have tried both nginx 0.8.46 and 0.8.52 to reverse proxy a URI that
contains a whitespace, but I’m having no luck. Any URI without a space
loads just fine, but one that contains a white space results in a “Bad
Request - HTTP Error 400. The request is badly formed.”

I had verified that the patch referenced above was in the source of
0.8.46. [The %20 substitution was missing from the proxy module so I
added it, but adding that substitution didn’t help.]

Are any of you folks able to reverse proxy a white space URI like
http://forum.nginx.org/siteX/storage/Nice Images/test-image.jpg” That’s
not a valid URI. I just wanted to give an example that shows the type of
white space that is in my URI.

thanks,
Chris

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,134985#msg-134985

Thanks Matthieu. I’ve applied your patch, but unfortunately the
behaviour remains the same.

This format of link doesn’t work. It reports a badly formed request:
http://www.xxxxx.xxx/us/storage/113/images/Member%20Images/image-2-web.png

But this better formatted URI does:
http://www.xxxx.xxx/us/storage/113/images/blog/child-eating-health-food.jpg

While it’d be nice to eliminate all white space from the source URI, I
do not have control over the source file structure/system.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,135016#msg-135016

As I said, my patch modifies the behavior to accept single ‘%’
(percent) in the url, not spaces. But maybe you can take inspiration
from that and apply it to your own case.

Hi,

I was in a similar situation trying to reverse proxy to a site that
has single percent signs in the url, which aren’t part of a url
encoding.
I did a quick patch to allow that, maybe this can help you.

Matthieu.

Glad to do so!

from nginx.conf
upstream backendcms {
server 172.26.161.230;
}

from my location specific conf
location ~* ^/us(.*)? {
proxy_set_header Host xxx.xxx.xxx;
proxy_pass http://backendcms$1;
subs_filter …
}

It truly is the white-space causing the issue because I copied the
“Member Images” folder to “Member-Images”. Trying the URI with the
hypen works and with the %20 does not.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,135025#msg-135025

On Tue, Sep 28, 2010 at 01:06:36PM -0400, cgarver wrote:

proxy_pass       http://backendcms$1;
subs_filter     .....

}

It truly is the white-space causing the issue because I copied the
“Member Images” folder to “Member-Images”. Trying the URI with the
hypen works and with the %20 does not.

The 400 error is sent by backend because backend does not support
unencoded
spaces in URI. nginx can espace it, if you will use

location ^~ /us {
proxy_pass http://backendcms/;
proxy_set_header Host xxx.xxx.xxx;
subs_filter …
}


Igor S.
http://sysoev.ru/en/

Thanks, but when I try that I cannot get nginx to start.

/etc/init.d/nginx restart
[emerg]: “proxy_pass” may not have URI part in location given by regular
expression, or inside named location, or inside the “if” statement, or
inside the “limit_except” block in /etc/nginx/national_sites.conf:4
configuration file /etc/nginx/nginx.conf test failed

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,135037#msg-135037

On Tue, Sep 28, 2010 at 01:24:25PM -0400, cgarver wrote:

Thanks, but when I try that I cannot get nginx to start.

/etc/init.d/nginx restart
[emerg]: “proxy_pass” may not have URI part in location given by regular
expression, or inside named location, or inside the “if” statement, or
inside the “limit_except” block in /etc/nginx/national_sites.conf:4
configuration file /etc/nginx/nginx.conf test failed

You should use

  location ^~ /us {


Igor S.
http://sysoev.ru/en/

On Tue, Sep 28, 2010 at 10:24:03AM -0400, cgarver wrote:

http://forum.nginx.org/siteX/storage/Nice Images/test-image.jpg”
That’s not a valid URI. I just wanted to give an example that shows the
type of white space that is in my URI.

Could you show proxy_pass directive ?


Igor S.
http://sysoev.ru/en/

Sorry to be a pain, but I cannot claim success yet.

The good news - the image now appears.

The bad news - the /us/ is now case sensitive and the www.xxxx.xxx/us/
site never returns. It’s in some kind of loop. A page further down
like www.xxxx.xxx/us/some-directory/some-page will work.

location ^~ /us {
proxy_pass http://backendcms/;
proxy_set_header Host xxx.xxx.xxx;
subs_filter …

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,135046#msg-135046

On Tue, Sep 28, 2010 at 01:37:01PM -0400, cgarver wrote:

proxy_set_header Host xxx.xxx.xxx;
subs_filter      ....

You have to create 4 locations:

location ^~ /us {
location ^~ /US {
location ^~ /Us {
location ^~ /uS {


Igor S.
http://sysoev.ru/en/

The problem with the looping was that I needed to update my subs_filter
to eliminate the leading slash in pattern matches. So, it is now
working very well except it is case sensitive which is bound to cause
some issues. Is there a rewrite I can do to force the request to
lowercase without killing server performance?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,135050#msg-135050

On Tue, Sep 28, 2010 at 02:14:09PM -0400, cgarver wrote:

will be any pitfalls later…
Then

rewrite (?i)^/us(.)$ /us$1 last;
rewrite (?i)^/ca(.
)$ /ca$1 last;


Igor S.
http://sysoev.ru/en/

As I have other countries like Canada to deal with, it can get rather
unwieldy doing every permutation of case. What about something like
this:

rewrite (?i)^/us(.*)$ /us$1;
location ^~ /us {
proxy_pass http://backendcms/;
proxy_set_header Host xxx.xxx.xxx;

It seems to be allowing www.xxxx.xxx/uS/ to work. Not sure if there
will be any pitfalls later…

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,135058#msg-135058

Works like a champ! Thanks for your help.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,97031,135070#msg-135070

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs