Help with configuring nginx for rewrites.
I've just recently set up an nginx webserver after reading about it being better with resources than Apache.
Having experience with Apache before (my shared hosting uses Apache) working in the nginx environment is completely new to me o.O
I'm trying to install SpaceBukkit on my Linode for Minecraft Server management, and am struggling as to where to put:
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;
}
Spacebukkit is located in a directory (sub.domain.tld/admin) of the server_name (sub.domain.tld) and adding /admin behind every tag doesn't seem to function and gives an error 500 code. How may I modify the above code to function in a directory?
Thanks!
EDIT: Also, I'd like it so that if users visit the site via another domain (such as domain.tld/minecraft/admin) they would be able to access the site with the rewrite rules applied.
It's like having a .htaccess in the directory, but since nginx doesn't support .htaccess… oh well
3 Replies
location / {
root /app/webroot;
index index.php /index.php;
try_file $url $url/ ;
}
location /app/ {
root webroot ;
try_files $url ;
}
location /app/webroot/ {
try_files $url $url/ /index.php?$uri&$args ;
}
Untested but you get the gist
The config I used is derived from the script's webpage:
EDIT:
I guess I wasn't specific enough. After hours upon hours of tinkering with the configurations, I am still unable to accomplish the simple task of modifying the configuration so that it works in a subdirectory.
My latest attempt, this, doesn't work at all
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /var/www/minecraft;
index index.php;
# Make site accessible from _
server_name _;
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;
}
location ~* \.php$ {
try_files $uri = 404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/phpfpm.sock;
fastcgi_index index.php;
}
}
just google cakephp on nginx. there is no rewrite really need for nginx. just point your domain root into webroot directory
….
location / {
root /var/www/example.com/public/app/webroot/;
index index.php index.html index.htm;
if (-f $request_filename) {
break;
}
….