This article is about setting up Nginx + PHP-FastCGI on Debian 6.0.6 Squeeze

Step1. Install nginx and php5-cgi :

apt-get install nginx php5-cgi

Step2. Replace Nginx default virtualhosts config with the following content:

server {
listen [::]:80;
server_name debian-tutorials.com;
root /var/www/debian-tutorials.com;
index index.html index.htm index.php;
access_log /var/log/debian-tutorials.com.access.log;

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/tmp/php.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

NOTE: Replace debian-tutorials.com with your own domain.

Step3. Create a  Debian init script to control the php-cgi daemon.

Continue Reading…

If you run an Apache2  server then you have no doubt seen the following error messages a thousand times in your error.log file:

File does not exist: /var/www/robots.txt

File does not exist: /var/www/favicon.ico

As you know by now  not having a favicon.ico file  web browsers will requesting  it each time. But you can tell Apache2  not to log the event as a mistake message.

You will still see the request in the access.log, but at least you will have a cleaner error.log file.

Solution:

Continue Reading…

This is my favorite and I think the more simple  if you want permanent redirect  from NON WWW to WWW insert the following code in the nginx configuration file nginx.conf :

server {
  listen 80;
  server_name www.debian-tutorials.com;
  rewrite ^/(.*)$ http://debian-tutorials.com/$1 permanent;
}
Permanent redirect from WWW to NON WWW in nginx, use this code in your nginx.conf :
server {
  listen 80;
  server_name debian-tutorials.com;
  rewrite ^/(.*)$ http://www.debian-tutorials.com/$1 permanent;
}

Enjoy!

For the sake of SEO is better to have one URL for each post or article on your site, like having two uris respond with the same content can lead to duplicate content and is penalized by search engines, especially Google, which is the largest by far.

Therefore, if you’re using Nginx and want to remove the trailing slash at the end of every URI in your site.

So if someone writes:

http://yoursite.com/ will be automatically redirected to http://yoursite.com

Here is the code needed to put it in your nginx.conf.

rewrite ^/(.*)/$ /$1 permanent;

That goes in the server section so something like this:

server {
listen  :80;
server_name  www.yoursite.com;
rewrite ^/(.*)/$ /$1 permanent;
}

Nginx will handle the trailing slashes now.

Nginx Canonical Domain

Valic —  July 19, 2011 — Leave a comment
############# www to non-www
server{
  listen 80;
  server_name  www.debian-tutorials.com;
  rewrite ^(.*) http://debian-tutorials.com$1 permanent;
}

############# non-www to www
server {
  if ($host ~* ^([a-z0-9\-]+\.(com|net|org))$) {
    set $host_with_www www.$1;
    rewrite ^(.*)$ http://$host_with_www$1 permanent;
  }
}

Enjoy
Page 2 of 3123