Activities

February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Nginx : Setting up custom error pages

Add the following line in your virtualhost config. file for your domain.

error_page 500 502 503 504 404  /404.html;
        location = /404.html {
         root  /var/www/vhosts/mydomain.com/httpdocs/;
     }

Pls note that you have a file created on httpdocs named “404.html”. For setting this up on a joomla site little complicated.
these lines should be added at the end of the redirection urls condition fails. Sample entries are shown here,

server {
listen 73.228.17.64:80;
server_name www.mydomain.com mydomain.com;
access_log /var/log/httpd/nginx.access.mydomain.com.log;
error_log /var/log/httpd/nginx.errors.mydomain.com.log warn;
large_client_header_buffers 4 8k; # prevent some 400 errors
root /var/www/vhosts/mydomain.com/httpdocs;
index index.php index.html;

location / {
expires 30d;
error_page 404 = @joomla;
log_not_found off;
}

location @joomla {
rewrite ^(.*)$ /index.php?q=$1 last;
}

error_page 500 502 503 504 404 /404.html;
location = /404.html {
root /var/www/vhosts/mydomain.com/httpdocs/;
}

location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/vhosts/mydomain.com/httpdocs$fastcgi_script_name;
include fastcgi_params;
}

location ~* ^.+.(swf|zip|rar|html|htm|pdf)$ {
root /var/www/vhosts/mydomain.com/httpdocs/;
expires 7d;
}
}

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>