WordPress Permalinks on Nginx
May 28, 2009 by Mark
Filed under Open Source Software, Tips & Tricks
First open your nginx configuration file.
nano /etc/nginx/nginx.conf
But if you set up a virtual host, you should open the virtual host configuration for the host where you install wordpress. If you are using Debian, the configuration files is located at /etc/nginx/sites-available/. The following command should do that.
nano /etc/nginx/sites-available/example.com
Now find the section location / . Add the following code inside the curly brackets {}.
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
break; }
Below is virtual host sample configuration after adding the code above.
server {
listen 80;
server_name example.com;
error_log logs/error-example.log;
access_log logs/access-example.log;
location / {
root /var/www/example.com;
index index.html index.htm index.php;
#error_page 404 = /index.php?q=$request_uri;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
break; }
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/example.com$fastcgi_script_name;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Now save the file and close the text editor. The changes will not take effect until you restart nginx. It’s totally different from Apache where you can edit .htaccess and don’t need to restart Apache in order to apply the change. So run the following command the restart nginx.
/etc/init.d/nginx restart
Now you can log in to your wordpress blog and customize your permalinks to your liking.




Comments
One Response to “WordPress Permalinks on Nginx”Trackbacks
Check out what others are saying about this post...[...] To change it, go to Setting > Permalinks. Under Common settings click the radio button infront of Custom Structure. Then enter %postname%/ in the textbox. Hit the Save Changes button to apply the change. If your .htaccess is not writable, you have to edit the file manually and copy and paste the text inside the textbox below the Save Changes button. If you are using Nginx follow the instruction on my previous post WordPress Permalinks on Nginx. [...]