I have installed nginx 1.2.7 using the nginx repo on my CentOS box that also uses Virtualmin. Ideally I'll have multiple Virtualmin shared hosts using nginx and no apache; some vhosts running Drupal, some not. I can get *almost* everything to work at once but usually what happens is if I get one thing to work, something else breaks.

I've based my config mostly on the boost example because that seems the simplest and at this point I just want it to work. Here is my nginx config file, a sample vhost file for the first site I'm trying to set up, and the Drupal include file in each vhost site file. Any help would be much appreciated. mysite.com represents my domain, and 4.2.2.2 represents my public IP (though it's not).

Basically what's happening now is I can *get to* the clean-url page, (and can check the box! as in, the test succeeds) but all else fails after checking the box. I get an empty 1x1 location (as specified in the config) upon submitting that form. Below these 3 config files is the latest error message.

nginx.conf

user nginx;
worker_processes 1;

error_log  /var/log/nginx/error.log info;
pid        /var/run/nginx.pid;


events {
    worker_connections  768;
}


http {
    include       /etc/nginx/mime.types;
	default_type application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    server_names_hash_bucket_size 128;
    index "index.php index.html";
}

vhost.conf

server {
    server_name mysite.com mysite.com;
 listen 80;
 root /home/mysite.com/public_html;
 index index.php index.html;
    access_log /var/log/virtualmin/mysite.com_access_log;
  error_log /var/log/virtualmin/mysite.com_error_log;
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
   fastcgi_param SERVER_SOFTWARE nginx;
   fastcgi_param QUERY_STRING $query_string;
  fastcgi_param REQUEST_METHOD $request_method;
  fastcgi_param CONTENT_TYPE $content_type;
  fastcgi_param CONTENT_LENGTH $content_length;
  fastcgi_param DOCUMENT_ROOT /home/mysite.com/public_html;
  fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
  fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param HTTPS $https;
 
   location ~ .php$ {
        fastcgi_pass unix:/var/php-nginx/13627035037928.sock/socket;
   }
  include drupal7;
   listen 443 default ssl;
 ssl_certificate /home/mysite.com/ssl.cert;
 ssl_certificate_key /home/mysite.com/ssl.key;
}

the /etc/nginx/drupal7 file:

charset utf-8;
 
  # search for already compressed files
  gzip_static on;
  gzip on;
 
  # some images have no mime type
  default_type image/jpeg;
 
  # Buffers definition. allows of up to 260k to be passed in memory.
  client_body_buffer_size 1m;
  proxy_buffering on;
  proxy_buffer_size 4k;
  proxy_buffers 8 32k;
 
  # 404 generated from php can be rather slow. Uncomment with care
  #error_page  404              /index.php;
 
  # disallow access to version control directory, but return 404, not to disclose information
  location /.git {
    return 404;
  }
 
  # robots.txt is important for search engines
  location /robots.txt {
    access_log off;
  }
 
  # This is mostly based on Drupal's stock .htaccess
  location ~* ^.+(.(txt|engine|inc|info|install|module|profile|po|sh|.<em>sql|theme|tpl(.php)?|xtmpl)|code-style.pl|/Entries.</em>|/Repository|/Root|/Tag|/Template)$ {
    return 404;
  }
 
  # serve imagecache files directly or redirect to drupal if they do not exist
  location ~* imagecache {
    access_log off;
    expires 30d;
    try_files $uri @drupal;
  }
 
  # Drupal 7 image stylef
  location ~* image/generate {
    access_log off;
    expires 30d;
    try_files $uri @drupal;
  }
 
  # serve static files directly
  location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|swf|flv)$ {
    access_log        off;
    expires           30d;
  }
  try_files $uri $uri/ /index.php?q=$uri&$args;
 
  # This rewrites pages to be sent to PHP processing
  location @drupal {
    index index.php;
  }
 
  location ~* ^/(apc|info).php$ {
    auth_basic "Restricted Area";
    auth_basic_user_file htpasswd;
    include fastcgi_params;
}
 
  location ~* ^.+.php$ {
    return 404;
  }
 
  # only a few php files are allowed, this increases the overall server security
  location ~* ^/(index|boost_stats|cron|xmlrpc).php$ {
    include fastcgi_params;
  }
 
  # internal pages are protected with a simple htpasswd
  location ~* ^/(install|update|memcached|apc|info).php$ {
    auth_basic "Restricted Area";
    auth_basic_user_file htpasswd;
    include fastcgi_params;
  }
 
  location ~* ^.+.php$ {
    return 404;
  }

And the elusive error in /var/log/virtualmin/mysite.com_error_log:

[error] 7733#0: *2 open() "/home/mysite.com/public_html/admin/config/search/clean-urls/check" failed (2: No such file or directory), client: 1.2.3.4, server: mysite.com, request: "GET /admin/config/search/clean-urls/check HTTP/1.0", host: "mysite.com"

Again, any help will be super appreciated. I would love to return the favour if you're able to help me.

EDIT: I have updated the code to what I have working, for now.

Comments

trogie’s picture

For clean urls you'll need the 'rewrite' nginx module and minimal this in your 'vhost' configuration file:

        location / {
                # This is cool because no php is touched for static content
                try_files $uri @rewrite;
        }
 
        location @rewrite {
                # Some modules enforce no slash (/) at the end of the URL
                # Else this rewrite block wouldn't be needed (GlobalRedirect)
                rewrite ^/(.*)$ /index.php?q=$1;
        }
scottm316’s picture

For completeness, in case anyone is searching for more examples, the other referenced file called fastcgi_params, has the contents:

fastcgi_params:

fastcgi_param  QUERY_STRING       q=$uri&$args;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
fastcgi_intercept_errors on;

## Allow 4 hrs - pass timeout responsibility to upstream.
fastcgi_read_timeout 14400;
fastcgi_index index.php;

## Hide the X-Drupal-Cache header provided by Pressflow.
fastcgi_hide_header 'X-Drupal-Cache';

## Hide the Drupal 7 header X-Generator.
fastcgi_hide_header 'X-Generator';

Scott
http://morrisonmultimedia.ca/
Edmonton, AB

scottm316’s picture

I've since made my beginner config generic enough to share on github. Feedback, comments and questions are always welcome! It's a scaled down version of perusio's but still has most of the options available in comments.

View on github

Like I said, feedback welcome!

Scott
http://morrisonmultimedia.ca/
Edmonton, AB