Forum: NGINX Issue with Upstream servers & GeoIP

F32978453eb8341e2e04249bc36220d4?d=identicon&s=25 Alex (Guest)
on 2014-03-26 03:26
(Received via mailing list)
I am diverting traffic from one specific country (XX) to a specific APP
server (Server for country XX) using an upstream definition and geoip.
See
definition below.

Everything works well except when people who live in country XX try to
access information that is hosted in the other server - this is because
they may get the URI by doing searching on Google or other search
engine.
So we are trying to set Nginx so that if we get a URI that is hosted in
the other server, the user from country XX can still access it.  See the
"FUN" location definition.

The problem comes when the person located in country XX sees the
domain.com/fun uri.  Then, he/she gets all the text, but any reference
of
css, jpegs are served by server from country XX, not by the standard
server that contains the :fun" information.  How can I set it so that is
being accessed be served entirely by the appropriate server that hosts
the
information?

Here is a partial definition of my nginx.conf file


       ##
        # GeoIP Settings
        ##
        geoip_country  /pathto/GeoIP.dat;

#CREATE A MAP FOR GEOTARGET SESSIONS WITH GEOIP COUNTRY CODE
 map $geoip_country_code $backend {
    default default;
    XX XX;
}

# SERVER DEFINITIONS

#UPSTREAM SERVERS ONE FOR STANDARD SITE & OTHER FOR SOCIAL NETWORK

    upstream default.backend {
        server 192.192.192.192:80; #Standard Server for all countries
    }
    upstream XX.backend {
        server 193.193.193.193:80; #Server for  country XX.
    }


  server {

listen       80;
server_name  domain.com;

#FOR PEOPLE WHO LIVE IN COUNTRY XX WHEN THEY ACCESS anything with fun on
the URI we should let the default server handle the requests.
location ^~ /fun/ {
            proxy_pass         http://default.backend$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;

}


location / {
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_pass http://$backend.backend;

             }

             }
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-03-26 12:04
(Received via mailing list)
Hello!

On Wed, Mar 26, 2014 at 02:25:21AM -0000, Alex wrote:

>
> The problem comes when the person located in country XX sees the
> domain.com/fun uri.  Then, he/she gets all the text, but any reference of
> css, jpegs are served by server from country XX, not by the standard
> server that contains the :fun" information.  How can I set it so that is
> being accessed be served entirely by the appropriate server that hosts the
> information?

An obvious solution would be to return appropriate refernces to
css/jpegs/etc from your "standard server".

--
Maxim Dounin
http://nginx.org/
F32978453eb8341e2e04249bc36220d4?d=identicon&s=25 Alex (Guest)
on 2014-03-26 22:56
(Received via mailing list)
Maxinm -

Thank you for your answer!  It is not a root location issue because if I
am not in the country that is being geotargetted then I can see css,
etc.
everything without any problems.

The issue comes when the user is in country XX and sees that page.  If I
look at the error messages on the page I get a lot of 404s for images
and
css and js because they can not be found since all css are being served
by
the server in country XX and that server does not have it.

I tested this by creating a location with a string that all the images
references contain and point it to be served by the server outside of
the
country XX and all images display perfectly.

How can I circumvent this problem?

Alex
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.