rewrite ^/.well-known/caldav /dav redirect;
rewrite ^/.well-known/carddav /dav redirect;

location /dav {
  alias       /usr/share/grommunio-dav/server.php;
  access_log  /var/log/nginx/nginx-dav-access.log;
  error_log   /var/log/nginx/nginx-dav-error.log;
  fastcgi_param PHP_FLAG "
    output_buffering=off
    magic_quotes_gpc=off
    always_populate_raw_post_data=off
    mbstring.func_overload=off
  ";
  fastcgi_param PHP_VALUE "
    memory_limit=256M
    max_execution_time=259200
    zend.exception_ignore_args=On
    zend.exception_string_param_max_len=0
  ";
  include fastcgi_params;
  fastcgi_param REMOTE_USER "";
  fastcgi_index server.php;
  fastcgi_pass fpm_dav;
  fastcgi_param HTTP_PROXY "";
  fastcgi_param SCRIPT_FILENAME $document_root$1;
  fastcgi_intercept_errors off;
  fastcgi_read_timeout 360;
  include /etc/nginx/conf.d/grommunio_dav-*.conf.include;
}

location ~* /dav/.*\.(css|js|gif|jpe?g|png)$ {
  access_log  /var/log/nginx/nginx-dav-access.log;
  error_log   /var/log/nginx/nginx-dav-error.log;
  expires 1y;
  add_header Pragma public;
  add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  fastcgi_hide_header Set-Cookie;
}

location ~ /dav/(\.ht|Core|Specific) {
  access_log  /var/log/nginx/nginx-dav-access.log;
  error_log   /var/log/nginx/nginx-dav-error.log;
  access_log off;
  log_not_found off;
  deny all;
}
