Nginx将每个域的访问日志分开

时间:2017-02-21 21:04:50

标签: typo3-6.2.x access-log awstats

我将Nginx与Typo3结合使用。我的Typo3安装大约有8个域名。一切都像魅力一样。现在我遇到的问题是我想使用AWStats为每个域工作,但我不知道如何为每个域分隔访问日志。在下面,您可以看到我的配置实际上是如何运行的:

在站点内配置文件 - 可用:



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/*;
}




我试图在服务器块内分开它。但我不能让它发挥作用。这里有谁可以帮助我或提供一些提示?

1 个答案:

答案 0 :(得分:0)

每个server都可以覆盖它自己的访问日志位置:

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;
}