# Anything wrong with using 599, 598 error codes for logic?

**URL:** <https://www.ruby-forum.com/t/anything-wrong-with-using-599-598-error-codes-for-logic/171179>\
**Category:** NGINX\
**Created:** [June 27, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/anything-wrong-with-using-599-598-error-codes-for-logic/171179 "2009-06-27T19:47:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianmercer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/839c29/32.png) [@brianmercer](https://www.ruby-forum.com/u/brianmercer)\
**Post date:** [June 27, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/anything-wrong-with-using-599-598-error-codes-for-logic/171179/1 "2009-06-27T19:47:34Z")

</div>

I’m new here, thanks. I’m writing rules for Drupal using the Boost  
static caching module (like wp-super-cache). Is there anything wrong  
with using fake error codes like 599, 598 and internal locations to  
control logic?

server {  
listen 80;  
server\_name [example.com](http://example.com);  
access\_log /var/log/nginx/example.com.access.log;  
error\_log /var/log/nginx/example.com.error.log;  
root /var/example.com;  
index index.php;

if ($host !~\* ^([example.com](http://example.com))$ ) { # deny illegal host headers  
return 444;  
}

location / {  
rewrite ^/(.\*)/$ /$1 permanent; # remove trailing slashes for SEO  
error\_page 404 @drupal;

```
try_files $uri @cache;

```

}

location @cache {  
if ( $request\_method !~ GET ) {  
return 599;  
}  
if ($http\_cookie ~ “DRUPAL\_UID”) {  
return 599;  
}  
error\_page 599 = @drupal;

```
expires epoch;
add_header Cache-Control "must-revalidate, post-check=0, 

```

pre-check=0";  
charset utf-8;

```
try_files /cache/$host${uri}_$args.html @drupal;

```

}

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

location ~ .php$ {  
try\_files $uri @drupal; #check for existence of php file  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
}

location ~ .css$ {  
if ( $request\_method !~ GET ) {  
return 598;  
}  
if ($http\_cookie ~ “DRUPAL\_UID”) {  
return 598;  
}  
error\_page 598 = @x598;

```
access_log off;
error_log /dev/null crit; # prevent debugging if compiled 

```

–with-debug  
expires max; #if using aggregator

```
try_files /cache/$host${uri}_.css $uri @x404;

```

}

location ~ .js$ {  
if ( $request\_method !~ GET ) {  
return 598;  
}  
if ($http\_cookie ~ “DRUPAL\_UID”) {  
return 598;  
}  
error\_page 598 = @x598;

```
access_log off;
expires max; # if using aggregator

try_files /cache/$host${uri}_.js $uri @x404;

```

}

location @x598 {  
access\_log off;  
expires max; # max if using aggregator, otherwise sane expire time  
}

location ~\* ^.+.(jpg|jpeg|gif|png|ico)$ {  
if ($http\_referer !~ ^([http://example.com](http://example.com)) ) { # prevent image  
hijacking  
return 444;  
}

```
access_log off;
expires 45d;

try_files $uri @x404;

```

}

location @x404 {  
return 404;  
}

location ~ /. {  
deny all;  
}

location ~\*  
((cron.php|settings.php)|.(htaccess|engine|inc|info|install|module|profile|pl|po|sh|._sql|theme|tpl(.php)?|xtmpl)$|^(Entries._|Repository|Root|Tag|Template))$  
{  
deny all;  
}  
}

Posted at Nginx Forum:

> **[Anything wrong with using 599, 598 error codes for logic?](https://forum.nginx.org/read.php?2,3482,3482#msg-3482)**
>
> I'm new here, thanks. I'm writing rules for Drupal using the Boost static caching module (like wp-super-cache). Is there anything wrong with using fake error codes like 599, 598 and internal locations to control logic? \[code\] server { listen 80;...

---

<div class="post-metadata">

**Author:** ![brianmercer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/839c29/32.png) [@brianmercer](https://www.ruby-forum.com/u/brianmercer)\
**Post date:** [June 29, 2009, 1:18pm UTC](https://www.ruby-forum.com/t/anything-wrong-with-using-599-598-error-codes-for-logic/171179/2 "2009-06-29T13:18:17Z")

</div>

Hello!

On Sat, Jun 27, 2009 at 01:36:33PM -0400, brianmercer wrote:

> I’m new here, thanks. I’m writing rules for Drupal using the Boost static caching module (like wp-super-cache). Is there anything wrong with using fake error codes like 599, 598 and internal locations to control logic?

It should work with recent nginx versions (0.7.51+) but may  
produce strange results as long as this errors escape to user due  
to config errors. And actually I see no reason to do so in your  
config, 405 (Method Not Allowed) looks appropriate in your config.

> }  
> It’s much better to setup separate default server for this. E.g.

server {  
listen 80 default;  
server\_name\_in\_redirect off;

```
return 444;

```

}

> location / {  
> rewrite ^/(.\*)/$ /$1 permanent; # remove trailing slashes for SEO  
> error\_page 404 @drupal;
> 
> ```
> try_files $uri @cache;
> 
> ```

Directive error\_page seems unneeded here. Additionally it looks  
wrong (note that there is no ‘=’).

> ```
> return 598;
> try_files /cache/$host${uri}_.css $uri @x404;
> 
> ```
> 
> location ~\* ^.+.(jpg|jpeg|gif|png|ico)$ {  
> if ($http\_referer !~ ^([http://example.com](http://example.com)) ) { # prevent image hijacking  
> return 444;  
> }
> 
> ```
> access_log off;
> expires 45d;
> 
> try_files $uri @x404;
> 
> ```

It should be enough to use

```
try_files $uri =404;

```

instead as of 0.7.51+.

Maxim D.
