Welcome! Log In Create A New Profile

Advanced

Adapting rewrite to work in subdirectories.

Posted by Boon Pek 
Adapting rewrite to work in subdirectories.
March 05, 2012 10:37AM
Hi there!

I'm very new to nginx, but I'm proud to say that I'm a happy user (for its lower memory consumption, etc). One thing I find lacking here is the ability to have a .htaccess file (I know, it defeats the purpose of speed).

Right now, I'm setting up a admin panel for a game called Minecraft called SpaceBukkit. It's rewrite code is as follows:

location / {
index index.php /index.php;
rewrite (.*) /app/webroot$1 ;
}
location /app/ {
rewrite ^$ webroot/ ;
rewrite (.*) webroot$1 ;
}
location /app/webroot/ {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?$1 ;
}
index index.php /index.php;
}

Problem with this configuration is that it requires the files to be in the root directory. In my case, the root directory is taken by a map and I want to access the website via http://serveraddress/admin instead. I've tried adding /admin before the locations but with no avail.

Here's my current progress thus far with assistance from members of SpaceBukkit:
server {
root /var/www/minecraft;
index index.htm index.html index.php;

server_name _;

location / {
try_files $uri $uri/ =404;
}

location /admin {
alias /var/www/minecraft/;
index index.php;
}

location /admin/{
index index.php /index.php;
rewrite (.*) /app/webroot$1 ;
}

location /admin/app/ {
rewrite ^$ webroot/ ;
rewrite (.*) webroot$1 ;
}

location /admin/app/webroot/ {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?$1 ;
}
index index.php /index.php;
}
}

Thanks!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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