Welcome! Log In Create A New Profile

Advanced

Is if evil in this simple case?

Posted by strae 
Is if evil in this simple case?
April 15, 2011 08:27AM
I've read the ifIsEvil page and im now wondering if in my situation could cause problems.

I have an application that enable a subdomain for each user who register, something like posterous.
So, for every user I do:

1. create the system user
2. create folders and files
3. configure php-fpm to run the subomain with his user using a fcgi sock.

Nginx easily solve this with:

server_name ~^(?<domain>.+)\.test\.local$;
set $myhost app_$domain;
root /var/www/app/subdomains/$myhost/htdocs;
location / {
index index.php;
}
location ~* \.(gif|jpg|png|ico)$ {
expires 30d;
}
location ~ \.php$ {
fastcgi_pass unix:/var/web-sock/$myhost-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

But i need to check if the subdomain does exist, else use a default subdomain as fallback.
So my nginx site looks like:

server{
listen 80;
server_name ~^(?<domain>.+)\.test\.local$;

set $test_index /var/www/app/subdomains/app_$domain/htdocs/index.php;
set $myhost app_$domain;

if (!-f $test_index) {
set $domain 'default_fallback';
set $myhost 'default_fallback';
}

root /var/www/app/subdomains/$myhost/htdocs;
location / {
index index.php;
}
location ~* \.(gif|jpg|png|ico)$ {
expires 30d;
}
location ~ \.php$ {
fastcgi_pass unix:/var/web-sock/$myhost-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /status {
fastcgi_pass unix:/var/web-sock/$myhost-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}


Could that use of `if` cause problems?

I tryed to use try_files but I'm not been able to fit my need with it... and i dont know lua language at all; even if my needs will require a basic simple use of lua, i dont like to use languages that im not comfortable with..



Edited 1 time(s). Last edit at 04/15/2011 08:29AM by strae.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 300
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