Azure Ubuntu22.04部署NopCommerce遇权限异常问题求助
NopCommerce 4.60.3 Ubuntu 22.04 部署权限问题排查
问题场景
环境:Microsoft Azure云 Ubuntu 22.04,已安装HestiaCP控制面板,通过Hestia-NetCore模板配置.NET Core环境,示例应用运行正常。
操作:下载NopCommerce 4.60.3 Linux无源码版,解压至指定目录,配置服务以dotnet Nop.Web.dll启动。
报错:浏览器访问时抛出UnauthorizedAccessException,具体信息如下:
IOException: Permission denied Unknown location UnauthorizedAccessException: Access to the path '/home/test/web/store/netcoreapp/App_Data/DataProtectionKeys/key-acc685fa-d997-4794-9290-438a3e5c3e8d.xml' is denied. Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, string path, bool isDirError) CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. For more information go to http://aka.ms/dataprotectionwarning Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(byte[] plaintext)
问题解答
1. 需要设置写入权限的文件夹
App_Data目录及其所有子目录:包含DataProtectionKeys(存储数据加密密钥)、Logs(运行日志)、Plugins(插件文件)、TempUploads(临时上传文件)等核心存储目录wwwroot/content、wwwroot/images:用于存储静态资源、用户上传的商品图片等内容
2. 正确的权限设置方案
首先确认运行NopCommerce的进程用户:HestiaCP环境中,.NET Core应用通常由www-data用户或网站专属用户(如示例中的test)运行,可通过以下命令查看:
ps aux | grep dotnet
根据进程用户执行以下权限调整命令:
- 递归设置目录所有者为运行进程的用户和
www-data组(以www-data:www-data为例,若为网站专属用户则替换为test:www-data):sudo chown -R www-data:www-data /home/test/web/store/netcoreapp - 递归设置基础权限:目录755(可读可写可执行),文件644(可读可写):
sudo find /home/test/web/store/netcoreapp -type d -exec chmod 755 {} \; sudo find /home/test/web/store/netcoreapp -type f -exec chmod 644 {} \; - 对需要写入的核心目录追加权限:
sudo chmod -R 775 /home/test/web/store/netcoreapp/App_Data sudo chmod -R 775 /home/test/web/store/netcoreapp/wwwroot/content sudo chmod -R 775 /home/test/web/store/netcoreapp/wwwroot/images
当前设置azureuser:www-data报错,说明运行进程的用户并非azureuser,需根据实际进程用户调整所有者配置。
内容的提问来源于stack exchange,提问作者yvijay
相关产品推荐
相关产品推荐

