need help cleaning up user directory and php rules

mike mike503 at gmail.com
Sat Mar 14 21:25:10 MSK 2009


Is all you want the ability to have

foo.com/~username/ ?

If so I have it working a lot easier. Well, at least for ~mike. But
with the new regex location/etc. support it might be able to work
without that.

something like

location ^/~(.+) {
         root /home/$1/public_html/;
}

Perhaps? Not sure. I should probably try it but I'm too lazy. Igor
would probably know how to hack it quick.

On Sat, Mar 14, 2009 at 10:59 AM, Edho P Arief <edhoprima at gmail.com> wrote:
> ...and 10 hours later I fixed it by myself. Tested with most common
> cases, also ensured basic logic. Can be cleaned up better (or perhaps
> squash more bugs, if any) but I'm too sleepy right now.
>
> Also probably rather slow. My own connection is currently slow and I
> only tried this on remote system.
>
>
> server {
>        listen 80;
>        server_name genshiken.unit.itb.ac.id;
>        index index.php;
>        #change /usr/local/etc/nginx/ to default nginx root path
>        if ($request_filename ~
> ^/usr/local/etc/nginx//~([a-zA-Z0-9]*)(.*[^/]|)(/*)$) {
>                #$org_uri is old, unused variable but might have some
> use for improvement (or deletion)
>                set $org_uri $request_uri;
>                set $is_userdir 1;
>                set $newroot /home/$1/public_html;
>                set $homedir $1;
>                set $filedir $2;
>                set $slashes $3;
>                rewrite ^/~.* f~/;
>        }
>        if ($is_userdir != 1) {
>                set $newroot /usr/local/www/data;
>                #set to random string if not userdir (see above).
>                set $org_uri zxzz123;
>        }
>
>        root $newroot;
>
>        location f~/ {
>                #$is_ok: check wheter to apply rewrite or not at this
> and next location
>                set $is_ok 1;
>                if (-d /home/$homedir/public_html$filedir) {
>                        set $is_ok 2;
>                        rewrite ^f~/$ d~/;
>                }
>                if ($is_ok = 1) {
>                        rewrite ^f~/$ finaldest~/;
>                }
>        }
>
>        location d~/ {
>                #add slash for directory (if there's none yet - to
> avoid unwanted rewrite by nginx)
>                if ($slashes = "") {rewrite ^d~/$ /~$homedir$filedir/
> redirect; set $is_ok 1; }
>                if ($is_ok = 2) {rewrite ^d~/$ finaldest~/; set $is_ok 1; }
>        }
>
>        location finaldest~/ {
>                #extra: user-specific rewrite
>                if ($homedir = sampleuser) {rewrite ^finaldest~/$ sampleuser~/;}
>                #final destination (if there's no user-specific rewrite)
>                rewrite ^finaldest~/$ $filedir$slashes;
>        }
>
>        #user-specific rewrite block
>        location sampleuser~/ {
>                #or sampleuser~/$filedir$slashes; to get subfolder
> location ruling
>                rewrite ^sampleuser~/$ $filedir$slashes;
>                #wordpress. haven't able to make use of try_files or
> other modern mechanics yet
>                if (!-e $request_filename) {
>                        rewrite  ^(.*)$  /blog/index.php?q=$1  last;
>                        break;
>                }
>        }
>
>        #just a standard php block.
>        location ~ \.php$ {
>                if (!-f $document_root$fastcgi_script_name) { return
> 404; break; }
>                fastcgi_pass    127.0.0.1:9000;
>                fastcgi_index   index.php;
>                fastcgi_param   SCRIPT_FILENAME
> $document_root$fastcgi_script_name;
>                include fastcgi_params;
>        }
>
>
>
> --
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>
>


More information about the nginx mailing list