server {
server_name domain.com;
rewrite ^(.*)$ http://www.domain.com$1 permanent;
}
This entry was written by , posted on March 20, 2009 at 7:12 am, filed under http and tagged nginx. Leave a comment or view the discussion at the permalink.
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 , posted on March 9, 2009 at 10:30 pm, filed under Distro, http and tagged debian, linux, nginx, ulimit. Leave a comment or view the discussion at the permalink.
As read in Diamond Notes, Amazon is moving into CDN market with CloudFront.
This entry was written by , posted on November 25, 2008 at 11:46 pm, filed under http and tagged CDN. Leave a comment or view the discussion at the permalink.
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 , posted on November 14, 2008 at 11:28 am, filed under http and tagged nginx. Leave a comment or view the discussion at the permalink.
When you put your website in maintenance mode, it’s a good idea to return a HTTP 503 error code to the client.
This code indicates that “the server is currently unable to handle the request due to a temporary overloading or maintenance of the server”.
The 503 code is used to avoid crawlers or caching proxy use the maintenance page as the new valid content for the request. You certainly don’t want Google save this content in his search index as the content of your website
To achieve this we will use a rewrite rule in lighttpd to redirect all requests to a single PHP script which will return a 503 error code and print an informative message.
url.rewrite = ( "" => "/maintenance.php" )
This configuration will redirect any request to maintenance.php script.
If you need to serve an image in your maintenance page, you have to add another rule to the rewrite process like that :
url.rewrite = ( "upgrading.png" => "$0", "" => "/maintenance.php" )
It might be usefull to let admins or developers access the website during the maintenance.
For that, you can disable the maintenance rewrite rule for certain IP addresses :
$HTTP["remoteip"] != “192.168.1.42″ {
url.rewrite = ( "upgrading.png" => "$0",
"" => "/maintenance.php" )
}
<?php
header("HTTP/1.1 503 Service Unavailable");
?>
We're currently upgrading our servers...
This entry was written by , posted on July 22, 2008 at 2:28 am, filed under http and tagged lighttpd, php. Leave a comment or view the discussion at the permalink.
If you want to redirect visitors that access your website without the ‘www’, you can use mod_redirect with the following syntax:
$HTTP[”host”] =~ “^lescampeurs\.org” {
url.redirect = (
”^/(.*)$” => “http://www.lescampeurs.org/$1″
)
}
Links:
This entry was written by , posted on June 30, 2008 at 11:47 pm, filed under http and tagged lighttpd. Leave a comment or view the discussion at the permalink.
Cronolog is log rotation program which gives you a lot of options to template the log destination files. The common use is to split logs by year / month / day.
Here is how to configure Apache to send log entries to cronolog :
CustomLog "|/usr/sbin/cronolog /home/log/apache2/%Y-%m-%d_domain.com_access.log" combined
This will create a log file named 2008-06-02_domain.com_access.log for today.
Cronolog reads log entries from standard input and writes them to the output file specified by your template.
CustomLog "|/usr/sbin/cronolog /home/log/apache2/%Y-%m_domain.com_access.log" combined
CustomLog "|/usr/sbin/cronolog /home/log/apache2/%Y-%W_domain.com_access.log" combined
CustomLog "|/usr/sbin/cronolog /home/log/apache2/%H_domain.com_access.log" combined
This entry was written by , posted on June 4, 2008 at 7:33 am, filed under Logs, http and tagged apache, cronolog. Leave a comment or view the discussion at the permalink.
If you’re using SVN to control your web application, your certainly need to deny access to .svn sub-directories.
<DirectoryMatch "^/.*/\.svn/">
Order allow,deny
Deny from all
</DirectoryMatch>
$HTTP["url"] =~ "/\.svn/" {
url.access-deny = ( "" )
}
This entry was written by , posted on May 28, 2008 at 7:17 am, filed under http and tagged apache, lighttpd, svn. Leave a comment or view the discussion at the permalink.
After two years of using Pound, WordPress decided to switch to Nginx as software load balancers for WordPress.com. Read the full story on Barry’s Blog.
This entry was written by , posted on May 8, 2008 at 7:12 am, filed under http and tagged load balancer. Leave a comment or view the discussion at the permalink.
server.modules += ( "mod_redirect" )
$HTTP["host"] =~ "^domain\.com$" {
url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" )
}
$HTTP["host"] =~ "^www\.domain\.com$" {
url.redirect = ( "^/(.*)" => "http://domain.com/$1" )
}
$SERVER["socket"] == ":80" {
$HTTP["host"] =~ "(.*)" {
url.redirect = ( "^/(.*)" => "https://%1/$1" )
}
}
$HTTP["host"] =~ "^www1\.domain\.com" {
url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" )
}
Lets say that you want to redirect http://www.domain.com/party to http://blog.domain.com/party while you have a mod_rewrite rule on www.domain.com that redirect all URLs to a controller (“^(.*)$” => “/index.php$1″).
Your redirect will not work because mod_rewrite always execute before redirect rules. To bypass this, you need to use the $0 as the rule target to pass URLs through unmangled.
e.g.
url.redirect = ( "^/party(.*)" => "http://blog.domain.com/party$1" ) url.rewrite-once = ( "^/party" => "$0" )
tested with lighttpd 1.4.x
This entry was written by , posted on May 6, 2008 at 12:56 pm, filed under http and tagged lighttpd. Leave a comment or view the discussion at the permalink.