drupal+nginx: this works
J. Antas
antas at e-healthexpert.org
Tue Mar 17 02:14:21 MSK 2009
The following has been tested in a Drupal 6.10 + Ubuntu 8.10.
M.
The tests included calls to:
# http://clinica.0/index.php # ok
# http://clinica.0 # ok
# http://www.clinica.0 # ok
# http://clinica.0/user/password # ok
# http://clinica.0/test # Page not found
# http://nonexistant.clinica.0/ # Address Not Found
# http://clear.clinica.0/ # redirect to site "clearhealth"
#
# http://clinica.0/scripts/drupal.sh # 403 Forbidden
# http://clinica.0/scripts/code-style.pl # 403 Forbidden
# http://clinica.0/sites/default/files/ # 403 Forbidden
# http://clinica.0/sites/default/settings.php # 403 Forbidden
# http://clinica.0/sites/all/README.txt # show README.txt
# http://clinica.0/nice ports,/Trinity.txt.bak # Page not found
#
# http://www.clinica.0/benchtest.php # show a timed phpinfo (*)
# http://www.clinica.0/somefile.php # No input file specified.
# http://127.0.0.1/ # redirect to http://clinica.0
(*) see at the end of this email how benchtest.php was created
The file bellow does not fully take care of:
^/system/test/(.*)$ => /index.php?q=system/test/$1,
^/([^.?]*)\?(.*)$ => /index.php?q=$1&$2,
^/([^.?]*)$ => /index.php?q=$1
^/search/node/(.*)$" => /index.php?q=search/node/$1
### drupal-cgm file follows:
# --- cut here ---
# nginx - /etc/nginx/sites-available/drupal-cgm
#
server {
listen 80 default;
server_name _; # non defined server
return 444; # silently drop request
}
server {
listen clinica.0:80;
server_name www.clinica.0;
rewrite ^(.*) http://clinica.0$1 permanent;
}
server {
listen clinica.0:80;
server_name clinica.0;
access_log /var/log/nginx/drupal-cgm.access.log;
error_log /var/log/nginx/drupal-cgm.error.log;
root /var/www/drupal-cgm;
# restrict request methods to: GET|HEAD|POST
if ( $request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
break;
}
# hide drupal system files
location ~* ((cron\.php|settings\.php)
|\.(htaccess|engine|inc|info|install|module|profile|pl|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$
| ^(Entries.*|Repository|Root|Tag|Template))$ {
deny all;
}
# # rewrite domain name without the leading www.
# # we prefer the above "server_name www.clinica.0;" rewrite
# if ($host ~* ^www\.(.*)) {
# set $host_without_www $1;
# # bellow $1 contains '/foo', not 'www.mydomain.com/foo'
# rewrite ^(.*)$ http://$host_without_www$1 permanent;
# }
location / {
index index.php index.html;
error_page 404 = @drupal;
}
location @drupal {
# clean url rewrite for Drupal
rewrite ^(.*)$ /index.php?q=$1 last;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
# --- cut here ---
### benchtest.php file follows:
# --- cut here ---
sudo tee /var/www/drupal-cgm/benchtest.php <<-\EOA
<?php
// /var/www/drupal-cgm/benchtest.php
$start = microtime(true);
ob_start(); //Turn on output buffering
phpinfo();
$info = ob_get_clean();
echo "phpinfo() run time: ";
printf("%0.1f ms\n", (microtime(true)-$start)*1000);
echo $info;
ob_end_flush();
?>
EOA
# --- cut here ---
More information about the nginx
mailing list