Rapid Application Development with Open Source Software

Next: Installing Debug Kit for CakePHP UP: TOC

Let’s create a virtual host for ngnix in the command line. Open Terminal and run the following command:

su -

cd /usr/local/etc/nginx/
mkdir vhosts.d

vi /usr/local/etc/nginx/vhosts.d/logikfabrik.com.conf

vi /usr/local/etc/nginx/nginx.conf    ==> include vhosts.d

The file contains these configurations parameters.

server {                                                                                                                                   
   listen 80;                                                                                                                              
   server_name logikfabrik.com;                                                                                                            
   rewrite ^/(.*) http://www.logikfabrik.com/$1 permanent; # to prevent duplicate content                                                  
}                                                                                                                                          
                                                                                                                                           
server {                                                                                                                                   
    listen 80 ;
    server_name www.logikfabrik.com;
    client_max_body_size 10M;   # max size for uploading image files
    access_log /var/log/nginx-access-logikfabrik.log;
    error_log /var/log/nginx-error-logikfabrik.log;
    root /usr/local/www/logikfabrik.com/cakephp/app/webroot;   # point to cakephp webroot, refer to chapter setup CakePHP
    index index.php;

    # serve static files
    location / {
       try_files $uri $uri/ /index.php?$uri&$args;
    }

    location ^~ /awstats/ {
       alias /usr/local/www/logikfabrik.com/cakephp/app/webroot/awstats/;
    }
    location ^~ /awstatsicons/ {
       alias /usr/local/www/awstats/icons/;
    }

    location ~* \.php$ {      
       try_files $uri =404;
       include /usr/local/etc/nginx/fastcgi_params;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_intercept_errors on;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* \.php {
          try_files $uri =404;
          include /usr/local/etc/nginx/fastcgi_params;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_intercept_errors on;
          fastcgi_param SCRIPT_FILENAME  /document_root$fastcgi_script_name;
    }

    # Static files.
    # Set expire headers, Turn off access log
    location ~* \favicon.ico$ {
        access_log off;
        expires 7d;     # browser cache for 7 days
        add_header Cache-Control public;
    }
    location ~ ^/(img|cjs|ccss)/ {
        access_log off;
        expires 7d;
        add_header Cache-Control public;
    }

    # Deny access to .htaccess files, git & svn repositories, etc
    location ~ /(\.ht|\.git|\.svn) {
        deny  all;
    }

    location @no_cache {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

We need to restart nginx in order to make it work:

/usr/local/etc/rc.d/nginx restart Next: Installing Debug Kit for CakePHP UP: TOC