Welcome! Log In Create A New Profile


Allow use of root and alias together

Posted by rickb 
Allow use of root and alias together
March 12, 2010 05:03AM
Hi all,

First of all, I'm new here so ... hello!

I've started working on migrating a group of five co-hosted virtual-server websites. They all use different technology using PHP: Drupal, CMS Made Simple, plain XHTML, PHPMyAdmin, bespoke PHP webapps. I have worked hard to optimise the throughput using gzip (pre-)compression, JS/CSS minification etc. Nginx seems to be really strong on performance issues.

However, I have found the migration from Apache2 to Nginx to be a difficult process. In principle, the Nginx configuration is straight-forward, but there are gotchas that make the transition more difficult than it ought to be.

First, it took me a while to understand the two-phase search algorithm (first for the most-specific non-regular expression location, then for the regular expressions). Perhaps this is confusing because the location keyword is used for both. However, this isn't a major problem - just an observation that the learning curve is made worse. The answer is probably better documentation.

But there is one aspect I think needs a change. I found it difficult to express my existing rather complex Apache2 rules in Nginx because of the alias and the root command behaving in an uncooperative way. I have to use [i]root[/i] because I want PHP/FastCGI to work; without [i]root[/i], the PHP interpreter fails. I can use [i]root[/i] in a server block and [i]alias[/i] in a location block without any complaint from Nginx. This is normally OK, but it doesn't work for me in some cases because I have legacy websites that use aliases to meld old sections with a newer CMS. The URLs don't match the directory names exactly. So I was forced to rearrange the directories on the website so that the aliases map directly to URLs. Based on this, I have been able to achieve what I wanted.

This highlights a deficiency in Nginx: [i]alias[/i] does not set the document root, only [i]root[/i] does that. PHP pages won't work without the correct document root. But it is not possible to use pairs of [i]root[/i] and [i]alias[/i] statements in the same location block - Nginx rejects this.

I suggest that this limitation is relaxed. Where a [i]root[/i] statement appears, the document root should be set. Where an [i]alias[/i] statement appears, the mapping of URL to file path is established. These should not be mutually exclusive.

The alternative approach would be to make [i]alias[/i] set the document root also.

Sorry, only registered users may post in this forum.

Click here to login

Online Users

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