iRaS
iRaS

Reputation: 2136

Nginx user defined rewrite rules

I'm wondering why this is question got not asked before: I want let the user make her own rewrite rules but not editing his configuration file.

/etc/nginx/sites-enabled/example.com: this file (or the original as this file is a symlinkn to sites-available...) is only writeable for root.

As for apache2 we can give him a way to write own rewrite rules, other expires configuration and so on without the need to edit the configuration file in /etc. Let's say it is a hosting provider and the user can't even access the /etc directory...

Upvotes: 0

Views: 257

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42899

The whole .htaccess concept is not implemented in nginx, which one of the reasons why nginx is faster,

because if we have a file inside /var/www/site/folder1/folder2/file.php for example, the server needs to look for .htaccess inside folder2 and folder1 and site, and each will override the one above it, an overhead for each request.

The only way you might implement a kind of similar thing is add an include inside the config file that reads from a certain location

server {
   # bla bla
   include /var/www/site1/config.conf;
   location bla {
       # bla bla
   }
}

The config file would include server level directives,

Or you could just skip the server block and include files, and those files should include server blocks, but this isn't good because you give them access to the whole server, not just theirs. eg:

# /etc/nginx/sites-enabled/site-name
include /var/www/site1/site.conf
include /var/www/site2/site.conf
# etc

Basically, my advice, if you really need this functionality, install apache, and maybe just use nginx to server assets and proxy to apache.

Upvotes: 1

Related Questions