2

I use Nginx in combination with Typo3. My Typo3 installation has about 8 domains. Everything works like a charm. Now I have the problem that I want to use AWStats working for each domain but I don't know how can I separate the Access Log for every domain. In the following you can see how my configuration is actually running:

Config file inside sites-available:

server {
    listen        127.0.0.1:80;
    server_name    www.domain1.de
                       www.domain2.de
                       www.domain3.de
    root        "/var/www/oz/htdocs/";
    disable_symlinks if_not_owner;
    location ~ /\.ht {
        deny all;
    }

    location ~ ^/cgi-bin/ {
        deny all;
    }


    # PHP is enabled
    index index.php index.html index.htm;
    location ~ \.php(/|$) {
        try_files $fastcgi_script_name =404;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include /etc/nginx/fastcgi_params;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass unix:/var/www/oz/conf/sockets/nginx-php-fcgi.sock;
        fastcgi_read_timeout 300;
               fastcgi_buffer_size 128k;
               fastcgi_buffers 256 4k;
               fastcgi_busy_buffers_size 256k;
    }

    location = / {
        error_page    403 /.errorFiles/coming-soon.html;
    }
    location /.errorFiles/ {
        alias /usr/share/liveconfig/html/;
    }


#### NGINX Typo3 Config - Start #####


      location = /favicon.ico {
               log_not_found off;
               access_log off;
      }

      location = /robots.txt {
               allow all;
               log_not_found off;
               access_log off;
      }

      # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
      location ~ /\. {
               deny all;
               access_log off;
               log_not_found off;
      }

       client_max_body_size 200M;

       location ~ /\.(js|css)$ {
               expires 604800s;
       }

       location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
                expires 365d;
               
       }
        if (!-e $request_filename){
               rewrite ^/(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ /$1.$3 last;
       }

       location ~* ^/fileadmin/(.*/)?_recycler_/ {
               deny all;
       }
       location ~* ^/fileadmin/templates/.*(\.txt|\.ts)$ {
               deny all;
       }
       location ~* ^/typo3conf/ext/[^/]+/Resources/Private/ {
               deny all;
       }
       location ~* ^/(typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) {
       }

       location / {
                       if ($query_string ~ ".+") {
                               return 405;
                       }
                       if ($http_cookie ~ 'nc_staticfilecache|be_typo_user|fe_typo_user' ) {
                               return 405;
                       } # pass POST requests to PHP
                       if ($request_method !~ ^(GET|HEAD)$ ) {
                               return 405;
                       }
                       if ($http_pragma = 'no-cache') {
                               return 405;
                       }
                       if ($http_cache_control = 'no-cache') {
                               return 405;
                       }
                       error_page 405 = @nocache;

                       try_files /typo3temp/tx_ncstaticfilecache/$host${request_uri}index.html @nocache;
       }

       location @nocache {
                       try_files $uri $uri/ /index.php$is_args$args;
       }

#### NGINX Typo3 Config - End #####
}

server {
    listen        127.0.0.1:80;
    server_name    domain1.de;
    rewrite        ^/(.*)$ "http://www.domain1.de/$1" permanent;
}

server {
    listen        127.0.0.1:80;
    server_name    domain2.de;
    rewrite        ^/(.*)$ "http://www.domain2.de/$1" permanent;
}

server {
    listen        127.0.0.1:80;
    server_name    domain3.de;
    rewrite        ^/(.*)$ "http://www.domain3.de/$1" permanent;
}

nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
 worker_connections 5000;
 multi_accept on;
        use epoll;
}

http {

 ##
 # Basic Settings
 ##

 sendfile on;
 tcp_nopush on;
 tcp_nodelay on;
 keepalive_timeout 65;
 types_hash_max_size 2048;
 # server_tokens off;

 # server_names_hash_bucket_size 64;
 # server_name_in_redirect off;

 include /etc/nginx/mime.types;
 default_type application/octet-stream;

 ##
 # SSL Settings
 ##

# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
# ssl_prefer_server_ciphers on;

 ##
 # Logging Settings
 ##

 access_log /var/log/nginx/access.log;
 error_log /var/log/nginx/error.log;

 ##
 # Gzip Settings
 ##

 gzip on;
 gzip_disable "msie6";

 gzip_vary on;
 gzip_proxied any;
 gzip_comp_level 6;
 gzip_buffers 16 8k;
 gzip_http_version 1.1;
 gzip_min_length 256;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

 ##
 # Virtual Host Configs
 ##

 include /etc/nginx/conf.d/*.conf;
 include /etc/nginx/sites-enabled/*;
}

I tried to separate it inside the server-blocks. But I don't get it working. Anybody here who can help me or have some hints?

Rodia
  • 1,407
  • 8
  • 22
  • 29

1 Answers1

6

Each server can override it's own access log location:

server {
    listen        127.0.0.1:80;
    server_name    domain1.de;
    access_log /var/log/nginx/domain1-access.log;
    error_log  /var/log/nginx/domain1-error.log;
    rewrite        ^/(.*)$ "http://www.domain1.de/$1" permanent;
}

server {
    listen        127.0.0.1:80;
    server_name    domain2.de;
    access_log /var/log/nginx/domain2-access.log;
    error_log  /var/log/nginx/domain2-error.log;
    rewrite        ^/(.*)$ "http://www.domain2.de/$1" permanent;
}

server {
    listen        127.0.0.1:80;
    server_name    domain3.de;
    access_log /var/log/nginx/domain3-access.log;
    error_log  /var/log/nginx/domain3-error.log;
    rewrite        ^/(.*)$ "http://www.domain3.de/$1" permanent;
}
Jon
  • 1,715
  • 12
  • 14