"Internal Server Error" when trying to access to a SMB share

Nextcloud version (eg, 18.0.2): 18.0.4.2
Operating system and version (eg, Ubuntu 20.04): Fedora 31
Apache or nginx version (eg, Apache 2.4.25): Nginx 1.16.1
PHP version (eg, 7.1): 7.3.10

The issue you are facing:

“Internal Server Error” (From Nexcloud, not from Nginx) when trying to access to a SMB share.

  • This worked perfectly before and stopped to work suddenly.
  • the SMB server is FreeNAS-11.3-U2.1, and the share can be accessed successfully from outside Nextcloud.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Have a SMB share configured in “SERVER_URL/settings/admin/externalstorages”. This screen still show the configuration as valid. (Note: The share Nextcloud name is “SMB”)
  2. Try to access it in “SERVER_URL/remote.php/webdav/SMB”

The output of your Nextcloud log in “/var/log/nextcloud/nextcloud.log”:

{
  "reqId": "WiLEll5heBjXI5UF8evK",
  "level": 4,
  "time": "2020-04-29T08:14:13+00:00",
  "remoteAddr": "10.136.72.147",
  "user": "user",
  "app": "webdav",
  "method": "GET",
  "url": "/remote.php/webdav/SMB",
  "message": {
    "Exception": "Sabre\\DAV\\Exception",
    "Message": "Invalid request for / (InvalidTypeException)",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
        "line": 418,
        "function": "convertToSabreException",
        "class": "OCA\\DAV\\Connector\\Sabre\\File",
        "type": "->",
        "args": [
          {
            "__class__": "Icewind\\SMB\\Exception\\InvalidTypeException"
          }
        ]
      },
      {
        "file": "/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php",
        "line": 85,
        "function": "get",
        "class": "OCA\\DAV\\Connector\\Sabre\\File",
        "type": "->",
        "args": []
      },
      {
        "function": "httpGet",
        "class": "Sabre\\DAV\\CorePlugin",
        "type": "->",
        "args": [
          {
            "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
            "__class__": "Sabre\\HTTP\\Request"
          },
          {
            "__class__": "Sabre\\HTTP\\Response"
          }
        ]
      },
      {
        "file": "/var/www/nextcloud/3rdparty/sabre/event/lib/EventEmitterTrait.php",
        "line": 105,
        "function": "call_user_func_array",
        "args": [
          [
            {
              "__class__": "Sabre\\DAV\\CorePlugin"
            },
            "httpGet"
          ],
          [
            {
              "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
              "__class__": "Sabre\\HTTP\\Request"
            },
            {
              "__class__": "Sabre\\HTTP\\Response"
            }
          ]
        ]
      },
      {
        "file": "/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 479,
        "function": "emit",
        "class": "Sabre\\Event\\EventEmitter",
        "type": "->",
        "args": [
          "method:GET",
          [
            {
              "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
              "__class__": "Sabre\\HTTP\\Request"
            },
            {
              "__class__": "Sabre\\HTTP\\Response"
            }
          ]
        ]
      },
      {
        "file": "/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 254,
        "function": "invokeMethod",
        "class": "Sabre\\DAV\\Server",
        "type": "->",
        "args": [
          {
            "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
            "__class__": "Sabre\\HTTP\\Request"
          },
          {
            "__class__": "Sabre\\HTTP\\Response"
          }
        ]
      },
      {
        "file": "/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php",
        "line": 82,
        "function": "exec",
        "class": "Sabre\\DAV\\Server",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/nextcloud/remote.php",
        "line": 165,
        "args": [
          "/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php"
        ],
        "function": "require_once"
      }
    ],
    "File": "/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
    "Line": 659,
    "Previous": {
      "Exception": "Icewind\\SMB\\Exception\\InvalidTypeException",
      "Message": "Invalid request for / (InvalidTypeException)",
      "Code": 21,
      "Trace": [
        {
          "file": "/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php",
          "line": 66,
          "function": "fromMap",
          "class": "Icewind\\SMB\\Exception\\Exception",
          "type": "::",
          "args": [
            {
              "1": "Icewind\\SMB\\Exception\\ForbiddenException",
              "2": "Icewind\\SMB\\Exception\\NotFoundException",
              "13": "Icewind\\SMB\\Exception\\ForbiddenException",
              "16": "Icewind\\SMB\\Exception\\FileInUseException",
              "17": "Icewind\\SMB\\Exception\\AlreadyExistsException",
              "20": "Icewind\\SMB\\Exception\\InvalidTypeException",
              "21": "Icewind\\SMB\\Exception\\InvalidTypeException",
              "22": "Icewind\\SMB\\Exception\\InvalidArgumentException",
              "28": "Icewind\\SMB\\Exception\\OutOfSpaceException",
              "39": "Icewind\\SMB\\Exception\\NotEmptyException",
              "103": "Icewind\\SMB\\Exception\\ConnectionAbortedException",
              "104": "Icewind\\SMB\\Exception\\ConnectionResetException",
              "110": "Icewind\\SMB\\Exception\\TimedOutException",
              "111": "Icewind\\SMB\\Exception\\ConnectionRefusedException",
              "112": "Icewind\\SMB\\Exception\\HostDownException",
              "113": "Icewind\\SMB\\Exception\\NoRouteToHostException"
            },
            21,
            "/"
          ]
        },
        {
          "file": "/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php",
          "line": 78,
          "function": "handleError",
          "class": "Icewind\\SMB\\Native\\NativeState",
          "type": "->",
          "args": [
            "/"
          ]
        },
        {
          "file": "/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeState.php",
          "line": 212,
          "function": "testResult",
          "class": "Icewind\\SMB\\Native\\NativeState",
          "type": "->",
          "args": [
            false,
            "smb://tars.legion/smb/"
          ]
        },
        {
          "file": "/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php",
          "line": 263,
          "function": "open",
          "class": "Icewind\\SMB\\Native\\NativeState",
          "type": "->",
          "args": [
            "smb://tars.legion/smb/",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/apps/files_external/lib/Lib/Storage/SMB.php",
          "line": 416,
          "function": "read",
          "class": "Icewind\\SMB\\Native\\NativeShare",
          "type": "->",
          "args": [
            "/"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php",
          "line": 299,
          "function": "fopen",
          "class": "OCA\\Files_External\\Lib\\Storage\\SMB",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/PermissionsMask.php",
          "line": 122,
          "function": "fopen",
          "class": "OC\\Files\\Storage\\Wrapper\\Wrapper",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php",
          "line": 299,
          "function": "fopen",
          "class": "OC\\Files\\Storage\\Wrapper\\PermissionsMask",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Availability.php",
          "line": 314,
          "function": "fopen",
          "class": "OC\\Files\\Storage\\Wrapper\\Wrapper",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php",
          "line": 860,
          "function": "fopen",
          "class": "OC\\Files\\Storage\\Wrapper\\Availability",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php",
          "line": 929,
          "function": "readFirstBlock",
          "class": "OC\\Files\\Storage\\Wrapper\\Encryption",
          "type": "->",
          "args": [
            ""
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php",
          "line": 382,
          "function": "getHeader",
          "class": "OC\\Files\\Storage\\Wrapper\\Encryption",
          "type": "->",
          "args": [
            ""
          ]
        },
        {
          "file": "/var/www/nextcloud/apps/files_antivirus/lib/AvirWrapper.php",
          "line": 75,
          "function": "fopen",
          "class": "OC\\Files\\Storage\\Wrapper\\Encryption",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php",
          "line": 299,
          "function": "fopen",
          "class": "OCA\\Files_Antivirus\\AvirWrapper",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/View.php",
          "line": 1160,
          "function": "fopen",
          "class": "OC\\Files\\Storage\\Wrapper\\Wrapper",
          "type": "->",
          "args": [
            "",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Files/View.php",
          "line": 996,
          "function": "basicOperation",
          "class": "OC\\Files\\View",
          "type": "->",
          "args": [
            "fopen",
            "/SMB",
            [
              "read"
            ],
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
          "line": 416,
          "function": "fopen",
          "class": "OC\\Files\\View",
          "type": "->",
          "args": [
            "SMB",
            "r"
          ]
        },
        {
          "file": "/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php",
          "line": 85,
          "function": "get",
          "class": "OCA\\DAV\\Connector\\Sabre\\File",
          "type": "->",
          "args": []
        },
        {
          "function": "httpGet",
          "class": "Sabre\\DAV\\CorePlugin",
          "type": "->",
          "args": [
            {
              "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
              "__class__": "Sabre\\HTTP\\Request"
            },
            {
              "__class__": "Sabre\\HTTP\\Response"
            }
          ]
        },
        {
          "file": "/var/www/nextcloud/3rdparty/sabre/event/lib/EventEmitterTrait.php",
          "line": 105,
          "function": "call_user_func_array",
          "args": [
            [
              {
                "__class__": "Sabre\\DAV\\CorePlugin"
              },
              "httpGet"
            ],
            [
              {
                "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
                "__class__": "Sabre\\HTTP\\Request"
              },
              {
                "__class__": "Sabre\\HTTP\\Response"
              }
            ]
          ]
        },
        {
          "file": "/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
          "line": 479,
          "function": "emit",
          "class": "Sabre\\Event\\EventEmitter",
          "type": "->",
          "args": [
            "method:GET",
            [
              {
                "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
                "__class__": "Sabre\\HTTP\\Request"
              },
              {
                "__class__": "Sabre\\HTTP\\Response"
              }
            ]
          ]
        },
        {
          "file": "/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
          "line": 254,
          "function": "invokeMethod",
          "class": "Sabre\\DAV\\Server",
          "type": "->",
          "args": [
            {
              "absoluteUrl": "https://nextcloud.local/remote.php/webdav/SMB",
              "__class__": "Sabre\\HTTP\\Request"
            },
            {
              "__class__": "Sabre\\HTTP\\Response"
            }
          ]
        },
        {
          "file": "/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php",
          "line": 82,
          "function": "exec",
          "class": "Sabre\\DAV\\Server",
          "type": "->",
          "args": []
        },
        {
          "file": "/var/www/nextcloud/remote.php",
          "line": 165,
          "args": [
            "/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php"
          ],
          "function": "require_once"
        }
      ],
      "File": "/var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Exception/Exception.php",
      "Line": 30
    },
    "CustomMessage": "--"
  },
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0",
  "version": "18.0.4.2"
}

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'nextcloud.local',
  ),
  'logfile' => '/var/log/nextcloud/nextcloud.log',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
  ),
  'passwordsalt' => 'salt',
  'secret' => 'secret',
  'datadirectory' => '/var/lib/nextcloud/data',
  'dbtype' => 'pgsql',
  'version' => '18.0.4.2',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => '/var/run/postgresql',
  'dbport' => '',
  'dbtableprefix' => '',
  'dbuser' => 'nextcloud',
  'dbpassword' => '',
  'installed' => true,
  'instanceid' => 'instanceid',
  'ldapIgnoreNamingRules' => false,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'maintenance' => false,
  'loglevel' => 2,
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
  'mail_from_address' => 'user',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'mail.local'',
  'mail_smtpauthtype' => 'PLAIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'mail.local',
  'mail_smtpport' => '465',
  'mail_smtpname' => 'user',
  'mail_smtppassword' => 'password',
  'mail_smtpsecure' => 'ssl',
  'token_auth_enforced' => false,
  'theme' => '',
);

I have the exact same issue using the ESXi Image from hanssonit.se

When I add an smb external storage inside the nextcloud GUI, then despite the “green arrow” showing that the connection details are correct, it is not possible to access the share.

Issues range from error screens that the destination cannot be accessed, to being able to access the share but “you don’t have permission to add files” as well as “internal server error”.

The only way how I got it working was to use the smb-share script that comes with the ESXi image from hanssonit.se, which mounts the smb share in the OS, and then inside nextcloud that mountpoint is added as “local” external storage.

So all permissions are fine! But when you add the external storage as SMB inside the GUI of nextcloud it does not work.

My smb share is on an UNRAID nas.

There is an issue on GitHub for this, with some workaround solution in wait of a real fix: https://github.com/nextcloud/server/issues/20622