afurlan's blog

/^random (nerd|geek)? posts$/

Configuring apache's userdir on nginx

Wednesday, May 26, 2010 - Two comments

Today I moved the people.nullable.org from Apache to the Nginx and the migration was easier than I expected.

The configuration is very simple so I'll jump directly to the code. The following lines enables the Apache's Userdir feature with PHP support in a specific domain. As in my last post, I'm assuming you currently have PHP working on Nginx but if you don't, take a look at here to know how to do that using the spawn-fcgi.

server {
    server_name people.nullable.org;
    listen 80;
    listen 443;

    # directory root
    root /srv/people.nullable.org/nginx/www;
    index index.php index.html index.htm;

    # userdir redirection
    location ~ ^/~([^/]+)/(.+\.php)$ {
            if (!-f /home/$1/public_html/$2) {
                    rewrite ^ 404;
            }
            alias /home/$1/public_html/$2;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
    }
    location ~ ^/~([^/]+)(/.*)?$ {
            alias /home/$1/public_html$2;
            autoindex on;
    }

    # logging
    error_log /srv/people.nullable.org/nginx/log/access.log;
    access_log /srv/people.nullable.org/nginx/log/access.log;
}

There isn't too much to say, this setup is currently running on my server. Suggestions are welcomed! :)

Comments

  • gravatar-vinicius-massuchetto Massa, hein!? Não tenho tanta coragem pra migrar assim, em produção.

    /* Ps.: Talvez ficaria melhor:
    's/easier than I supposed/easier than I expected/g'
    's/I'm supposing you currently/I'm assuming you currently/g' */

    Abraços. =D
  • gravatar-arthur-furlan Done, thanks Vinicius. :)

Trackbacks