Getting WordPress set up with pretty urls on nginx is fairly straightforward. First thing we need to do is create a database for WordPress in MySQL and a user for this database.
mysql -u root -p
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO "user"@"localhost"
IDENTIFIED BY "pass";
FLUSH PRIVILEGES;
EXIT
Enter your MySQL root password when prompted and fill in your own values for user and pass.
Now that we have the database ready we can download and install WordPress.
wget http://wordpress.org/latest.tar.gz tar zxvf latest.tar.gz sudo cp -R /home/matt/wordpress/* /var/www/nginx-default/
Next we need to complete some configuration options for WordPress.
sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php
Fill in the details for DB_NAME, DB_USER and DB_PASSWORD that you created earlier (wordpress, user and pass in this example).
In order to get pretty urls to work in WordPress we have to set some rewrite rules in nginx. Edit the configuration file:
sudo nano /etc/nginx/sites-available/default
Edit the first location block so it looks like the following:
location / {
root /var/www/nginx-default;
index index.php index.html index.htm;
if (-f $request_filename) {
expires 30d;
break;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}
The first ‘if’ condition checks for static files and prevents their urls being rewritten. The second ‘if’ condition sends all urls to index.php. This allows you to set your own url scheme in WordPress under settings -> permalinks. Now restart nginx for the changes to take effect.
sudo /etc/init.d/nginx stop sudo /etc/init.d/nginx start
Finally browse to http://yourdomain.com/wp-admin/install.php and complete the WordPress install.
References:
http://elasticdog.com/2008/02/howto-install-wordpress-on-nginx/
