apache_nginx

Migrating Web Server From Apache To Nginx

Since two years ago (2007) this blog is hosted by Apache web server, and today I changed out the sofware in web server. I never had a “serious” problem with apache but I heard if nginx is a lightweight, high-performance HTTP server and reverse proxy. Nginx pronounced of engine-x also can handle static HTML, and does very well with dynamic (PHP) content as well. But nginx isn’t ideal for every server, nginx can’t handle SVN or WebDav, I’m still using apache for some situation :D.

Nginx is very impressive for simple virtualhost and standalone web server configuration, migrating wordpress from apache to nginx isn’t difficult. After installing nginx and setting up the virtualhost for my domain (blog.pnyet.web.id) I just copying my old files into home directory of my website and then change the permission also import mysql databases. Voila…, my blog is running well in nginx. But actually nginx isn’t support .htaccess or .htpasswd so I’ve reconfigure url rewriting for this website. Below is my virtualhost for this blog:

server {
listen      blog.pnyet.web.id:80;
server_name  blog.pnyet.web.id;

#charset koi8-r;

access_log  logs/blogp.access.log  main;
error_log   logs/blogp.error.log  debug;

location / {
root   /home/myweb01/public_html;
index  index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page  404              /404.html;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

location ~ \.php$ {
root           /home/myweb01/public_html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /home/myweb01/public_html;$fastcgi_script_name;
include        conf.d/fastcgi_params;
}

location ~ /\.ht {
deny  all;
}
}

server {
listen       blog.pnyet.web.id:443;
server_name  blog.pnyet.web.id;

access_log  logs/blogp_ssl.access.log  main;
error_log   logs/blogp_ssl.error.log  debug;

ssl                  off;
ssl_certificate      ssl/2011.crt;
ssl_certificate_key  ssl/2011.key;
ssl_session_timeout  5m;
ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers   on;

location / {
root   /home/myweb01/public_html;
index  index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page  404              /404.html;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

location ~ \.php$ {
root           /home/myweb01/public_html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME   /home/myweb01/public_html$fastcgi_script_name;
include        conf.d/fastcgi_params;
}
}

To enable url rewriting in nginx for wordpress i just add “try_files $uri $uri/ /index.php?q=$uri&$args;” and my permalinks working without any problem.

Cheers…

Leave a Reply

Your email address will not be published. Required fields are marked *


*