Configuration problem
Ruslan Ermilov
ru at nginx.com
Tue May 29 12:31:57 UTC 2012
On Tue, May 29, 2012 at 11:22:06AM +0100, Ian Hobson wrote:
> Hi All,
>
> I wish to configure phplist under nginx on multiple domains.
>
> phplist is installed into /lists in the root directory, and
> /lists/config/config.php is amended to give access to a php database.
>
> I though to move /lists to a location outside the normal web tree,
> replace /config/config.php with a script to test the domain name in
> $_SERVER, and load the appropriate configuration parameters.
>
> So the first job is to move /lists for one domain and get that working.
> The nginx configuration I have tried is this.
>
> # Statements for example.com virtual server
> server {
> listen 80;
> server_name example.com www.example.com;
> root /var/www/example.com/htdocs;
> access_log /var/www/example.com/access.log;
> index index.php index.html index.htm;
> location = /favicon.ico {
> log_not_found off;
> access_log off;
> }
> location = /robots.txt {
> allow all;
> log_not_found off;
> access_log off;
> }
> location ^~ /usage {
> auth_basic "Hello, please login";
> auth_basic_user_file /var/www/example.com/passwords;
> }
> location ^~ /lists {
> root /var/www/phplist;
> }
> location ~ \.php$ {
> include /etc/nginx/fastcgi_params;
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
> }
> try_files $uri $uri/ /index.php;
> }
>
> The idea being that the " location ^~ /lists {" stanza moves the root,
> and the "location ~ \.php$ {" stanza sends .php files off to fast_cgi,
> while nginx serves other assets from the relevant one of the two roots.
>
> Unfortunately, nginx serves the phplist php files, without passing them
> to fast_cgi, and the browser treats them as downloads. :(
>
> What is wrong with my configuration?
>
> Thanks
>
> Ian
Quoting http://nginx.org/r/location, "If the most specific prefix
location has the “^~” prefix then regular expressions are not checked."
In your case, if the request matches the prefix location "/lists",
you explicitly told nginx not to match it against regexp locations
including ".php$". "location /lists" would be a proper spelling.
Please also see
http://nginx.org/en/docs/http/request_processing.html#simple_php_site_configuration
for a working example.
More information about the nginx
mailing list