NginX

Virtual hosts with include directive

1. Create directory /etc/nginx/includes/

2. This dir will contain common config data

 

a) block .htaccess -- /etc/nginx/includes/htaccess.conf

#### /etc/nginx/includes/htaccess.conf

#deny access to Apache's .htaccess files
location ~ /\.htaccess {
    deny all;
}

 

b) php config --- /etc/nginx/includes/php.conf

#### /etc/nginx/includes/php.conf ####
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    #fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
}

c) Codeigniter framework -- /etc/nginx/includes/codeigniter.conf

#### /etc/nginx/includes/codeigniter.conf ####

# non existing files and dirs redirect to index.php
location / {
    try_files $uri $uri/ /index.php;
}

# disabling /system and /application in URL's
if ($request_uri ~* /system/?.*){
    rewrite ^(.*)$ /index.php?/$1 break;
}

if ($request_uri ~* /application/?.*){
    rewrite ^(.*)$ /index.php?/$1 break;
}

 

 

 

The final virtual host config file can be:

server {
    
  ############### General Settings ####################
    listen   80;
    server_name  www.adsuu.loc;
    root    "/homemiko/com_adsuu/www/pub/";
    index  index.php index.html;
    charset utf-8;
    autoindex on;
    error_log "/homemiko/com_adsuu/logs/www_adsuu_com_error.log";
    #access_log "/homemiko/com_adsuu/logs/www_adsuu_com_access.log";

    
  ################# Includes ##################

   include /etc/nginx/includes/htaccess.conf

   include /etc/nginx/includes/php.conf

   include /etc/nginx/includes/codeigniter.conf


}