Welcome! Log In Create A New Profile

Advanced

Re: if condition and question

Maxim Dounin
September 10, 2009 02:12PM
Hello!

On Thu, Sep 10, 2009 at 06:42:03PM +0200, Tomasz Pajor wrote:

> Hello,
>
> When a request comes to the server i want to check if the $remote_addr
> is in my list of addresses, if it is then serve the normal content if
> not, then serve a static page.
> I tried something like this but it doesn't seem to work.
>
> server {
> listen 80;
> server_name .app-domain.com;
> error_log /var/log/nginx/app-error.log;
>
> root /disk0/vhosts/app/public;
> charset utf-8;
>
> fastcgi_index index.php;
>
> location / {
> if ($remote_addr !~ (x.x.x.x|z.z.z.z|y.y.y.y)) {
> root /disk0/vhosts/blank;
> break;
> }
>
> try_files $uri $uri/ @fallback;
> fastcgi_pass apps;
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> include fastcgi_params;

This won't work as fastcgi_pass will be inherited into if(). You
should use internal redirect instead. Also it's a good idea to
use geo module for ip checks. So something like this should
work:

geo $static {
default 0;
x.x.x.x/32 1;
y.y.y.y/32 1;
z.z.z.z/32 1;
}

server {
...

location / {
if ($static) {
rewrite ^ /static/ last;
}
...
}

location /static/ {
internal;
alias /disk0/vhosts/blank/;
}

...
}

Maxim Dounin

> }
>
> location @fallback {
> fastcgi_pass apps;
> fastcgi_param SCRIPT_FILENAME $document_root/index.php;
> include fastcgi_params;
> }
> }
>
Subject Author Posted

if condition and question

Tomasz Pajor September 10, 2009 12:48PM

Re: if condition and question

Maxim Dounin September 10, 2009 02:12PM

Re: if condition and question

Igor Sysoev September 11, 2009 07:04AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 168
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready