Meselelerim-iz-
Epeycesi, şaka ciddi karışık
Anasayfa/Homepage Hakkımda/About Me Türkçe Yazılar Posts in English

Step by Step Nginx + Wordpress-mu Blog Service Creation - Step 2: Nginx, and MySql configuration

Saturday, 09 May 2009

Hi again. You are welcome to second stage!

Now, we must configure nginx, php and mysql.

Firstly, take a look to /etc/nginx/nginx.conf. You may want to increase worker_processes to a higher value than 1. Maybe 3 or 5. This identifies number of request handler processes.

Then add a virtual host to nginx. If you will use the server for only that site, then you may consider configuring default files. Default file is /etc/nginx/sites-available/default. This file includes server defaults, for example, if you want to give all your sites php support, then insert fastcgi parameters here. If you prefer a virtual host, adding it is quite simple. Create a config file to /etc/nginx/sites-available and link to that config from /etc/nginx/sites-enabled. That approach more tidy -in my opinion-, by the way.
#nano /etc/nginx/sites-available/your-site.com
#ln -s /etc/nginx/sites-available/your-site.com /etc/nginx/sites-enabled/your-site.com

This file must include at least:

server {
server_name your-site.com, www.your-site.com; #your domain
location / {
root /var/www/your-site.com; #/path/to/your-site.com/files
index index.html index.htm; #default index page
}
}

Great resource for config files: nginx wiki

And this is a config file for worpress-mu:
(This is not my own stuff, i merged from siava.su and this slicehost forum post. Thanks to them!)
(Assumed that your site directory includes two folders, first, logs for log files and second public for site root.)

server {
    listen 80;
    server_name your-domain.com *.your-domain.com; #requires a type wildcard dns entry
    access_log /var/www/your-domain.com/logs/access.log;
    error_log /var/www/your-domain.com/logs/error.log;
    error_page 500 502 503 504 /error/50x.html; #your error files
    client_max_body_size 16M; #for file uploads
#####Below wp-mu rewrite rules
   location ~* ^.+.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
    {
        root /var/www/your-domain.com/public;
        rewrite ^/.*(/wp-.*/.*.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
        rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ /wp-content/blogs.php?file=$1 last;
        expires 30d;
        break;
    }
    location / {
        root /var/www/your-domain.com/public;
        index index.php index.html;
        if (!-e $request_filename) {
            rewrite ^.+/?(/wp-.*) $1 last;
            rewrite ^.+/?(/.*.php)$ $1 last;
            rewrite ^(.+)$ /index.php?q=$1 last;
        }
#####Below for wp-super-cache
     # enable search for precompressed files ending in .gz
     # nginx needs to be complied using .-with-http_gzip_static_module
     # for this to work, comment out if using nginx from aptitude
     # gzip_static on;
     # if the requested file exists, return it immediately
        if (-f $request_filename) {
                break;
        }
        set $supercache_file '';
        set $supercache_uri $request_uri;
        if ($request_method = POST) {
                set $supercache_uri '';
        }
        # Using pretty permalinks, so bypass the cache for any query string
        if ($query_string) {
                set $supercache_uri '';
        }
        if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
                set $supercache_uri '';
        }
        # if we haven't bypassed the cache, specify our supercache file
        if ($supercache_uri ~ ^(.+)$) {
                set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
        }
        # only rewrite to the supercache file if it actually exists
        if (-f $document_root$supercache_file) {
                rewrite ^(.*)$ $supercache_file break;
        }
        # all other requests go to Wordpress
        if (!-e $request_filename) {
                rewrite . /index.php last;
        }
        }
    }
#####Finally php fastcgi
    location ~ .php$ {
        rewrite ^/.*(/wp-.*/.*.php)$ $1;
        fastcgi_pass 127.0.0.1:2345;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/your-site.com/public$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}

Change your-site.com to your domain, all done, pretty straight forward :)

wp-super-cache is a cache plugin for wordpress and wordpress-mu. Saves lots of cpu time.

I added some comments on config for explaining code blocks and some variables.

Now, an easy thing, add an user to mysql. This step is not essential, you give root user to wordpress-mu, but this is not a good way especially on production.
#mysql -u root -p
#create user 'user'@'localhost' identified by 'password';
#create database 'wordpress-mu-database';
#grant all on wordpress-mu-database.* to 'user'@'localhost';

Last line gives your user all privileges on wp-mu database, including drop! If you prefer, this line may be like this:

#grant create,alter,insert,update,delete on wordpress-mu-database.* to 'user'@'localhost';
This is obviously a better solution.

So far, we installed os, nginx, mysql and php. Configured nginx and mysql. Next article will cover php settings and making it running on boot.

hasan.cansiz.info @ 2009