Permanent redirect with nginx

server {
    server_name domain.com;
    rewrite ^(.*)$ http://www.domain.com$1 permanent;
}

This entry was written by CharlyBr, posted on March 20, 2009 at 7:12 am, filed under http and tagged . Leave a comment or view the discussion at the permalink.

Nginx and worker_connections are more than open file resource limit warning

If you encounter this warning message under Linux:

2009/03/09 21:23:19 [warn] 26827#0: 4096 worker_connections are more than open file resource limit: 1024

A solution is to use the command ulimit in nginx start script, just before lunching nginx:

[...]
ulimit  -n 65536
[...]

This entry was written by CharlyBr, posted on March 9, 2009 at 10:30 pm, filed under Distro, http and tagged , , , . Leave a comment or view the discussion at the permalink.

Fix nginx increase server_names_hash_bucket_size error

When adding new virtual hosts in your nginx configuration file, you can experience this error message:

# nginx -t
2008/11/13 09:37:03 [emerg] 12299#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
2008/11/13 09:37:03 [emerg] 12299#0: the configuration file /etc/nginx/nginx.conf test failed

server_names_hash_bucket_size controls the maximum length of a virtual host entry (ie the length of the domain name).

In other words, if your domain names are long, increase this parameter.

You need to add this flag in the http context:

http {
    server_names_hash_bucket_size 64;
    ...
}

After increasing the value, test your configuration file and reload nginx:

# nginx -t
2008/11/13 09:48:06 [info] 12315#0: the configuration file /etc/nginx/nginx.conf syntax is ok
2008/11/13 09:48:06 [info] 12315#0: the configuration file /etc/nginx/nginx.conf was tested successfully
# kill -HUP `cat /var/run/nginx.pid`

This entry was written by CharlyBr, posted on November 14, 2008 at 11:28 am, filed under http and tagged . Leave a comment or view the discussion at the permalink.

Rotate Nginx log files under FreeBSD

To rotate your nginx log files, you can use the log file handler provided by FreeBSD: newsyslog.

Configuring /etc/newsyslog.conf

/var/log/nginx-access.log               644  7     1024 *     JC /var/run/nginx.pid
/var/log/nginx-error.log                644  7     1024 *     JC /var/run/nginx.pid

Before log rotation:

-rw-r--r--  1 root  wheel    104278002 Jul 16 11:35 nginx-access.log
-rw-r--r--  1 root  wheel      1509531 Jul 16 11:17 nginx-error.log

After log rotation:

-rw-r--r--  1 root  wheel        967 Jul 16 12:42 nginx-access.log
-rw-r--r--  1 root  wheel    5310443 Jul 16 12:41 nginx-access.log.0.bz2
-rw-r--r--  1 root  wheel         77 Jul 16 12:41 nginx-error.log
-rw-r--r--  1 root  wheel      37552 Jul 16 12:41 nginx-error.log.0.bz2

Links

This entry was written by CharlyBr, posted on July 17, 2008 at 7:15 am, filed under Logs and tagged , , . Leave a comment or view the discussion at the permalink.