Location directive not working

I set up two upstream servers (server 1 and server 2) where I geotarget
people from specific countries: A

People from country A go to server 1 and the others go to server 2.

There are some uri s that must be served by server 1 when the person is
in
country A. So I have created this directive. It works only when I
include
one item, when I do (videos|events) it does not work

location ^~ /(videos|events) {
proxy_pass http://$server1$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

I do it this way because there are URLs that contain videos and events
that must be served by server 1. For example,
domain.com/videos/playing-with-my-dog etc. When I reload this directive
nginx does not give me any errors, but when I try to access it from
country B, it does not work.

Thanks for all your help!

Alex

On Wed, Mar 26, 2014 at 12:30:21AM -0000, Alex wrote:

Hi there,

It works only when I include
one item, when I do (videos|events) it does not work

location ^~ /(videos|events) {

That is not a regex location. A request for /videos/ will not match it.

http://nginx.org/r/location

f

Francis D. [email protected]

Francis -

Thank you for your reply!

This OR regex : location ~* .(gif|jpg|jpeg)$

works on jogs and gifs, why can not I use the same syntax for the URIs
as
I am doing it?

Does it mean then that I have to define each location block one by one
with different URIs even though all the information inside the location
block is the same? Is there a regex to match the OR condition just as
you
do with jogs?

Thanks for your help!

On Wed, Mar 26, 2014 at 12:31:30PM -0000, Alex wrote:

Hi there,

This OR regex : location ~* .(gif|jpg|jpeg)$

Which part of that line says that it is a regex?

(The answer is in the documentation.)

works on jogs and gifs, why can not I use the same syntax for the URIs as
I am doing it?

If you used the same syntax, it would probably work.

location ^~ /(videos|events) {

is not the same syntax.

Good luck with it,

f

Francis D. [email protected]

Francis -

What I meant was that I was using an OR statement as it is used in the
jpg
example. If I do this:

location ^~ /videos/ { # it works

location ^~ /(videos|events) { #it does not work. So I assume is the OR
that does not work.

Any thoughts?

Thanks,

Alex

Wow Francis.
You are a patient man. I love the way you teach things. I mean it all.

B. R.

On Wed, Mar 26, 2014 at 04:44:49PM -0000, Alex wrote:

Hi there,

location ^~ /(videos|events) { #it does not work. So I assume is the OR
that does not work.

Any thoughts?

The documentation is at http://nginx.org/r/location.

It’s all useful, but the fourth sentence is particularly relevant.

This OR regex : location ~* .(gif|jpg|jpeg)$

Which part of that line says that it is a regex?

When you know the answer to that question, you’ll probably see that the
various squiggles after the word “location” aren’t just random.

f

Francis D. [email protected]n.invalid

Thank you for your answer! I read the paragraph. I changed the
preceding
modifier to ~* and it works now.

I made a mistake addressing the OR condition and calling it regex sorry.

Thank you for your help!

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