Directory Aliasing on nginx

last few day, i migrated web server from apache to nginx. Not a big problem when i configuring php with nginx, but the main problem is, how to configuring alias directory in nginx ?.

on apache, configuring alias directory is quite simple, like this :

Alias /wiki "/usr/local/www/mediawiki"
<Directory /usr/local/www/mediawiki>
Options FollowSymLinks
AllowOverride None
order deny,allow
deny from all
allow from xxxxxxx/y

but, in nginx ?  harder than using apache :D. Here’s example how to enabling alias directory in nginx

location /wiki {
alias //usr/local/www/mediawiki;
index index.php;
location ~ /wiki/.*\.php$ {
if ($fastcgi_script_name ~ /wiki(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/mediawiki$valid_fastcgi_script_name;
include fastcgi_params;

save nginx.conf and restart nginx.

done! :p


2 responses to “Directory Aliasing on nginx

  1. i followed your example but it didn’t work as well…
    nginx: [emerg] unknown directive “if($fastcgi_script_name” in
    my conf is:
    server {
    listen 80 default;
    location /webmail {
    alias //home/www/roundcube;
    index index.php index.html;
    access_log /var/log/nginx/webmail.bibogame.lcl.access.log;
    error_log /var/log/nginx/webmail.bibogame.lcl.error.log debug;
    location ~ /webmail/.*\.php$ {
    if($fastcgi_script_name ~ /wiki(/.*\.php)$) {
    set $valid_fastcgi_script_name $1;
    include fastcgi_params;
    # Or use unix-socket with
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fast_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/www/roundcube/$valid_fastcgi_script_name;

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s