以编程方式在 azure 存储上启用静态网站

Jer*_*rry 3 azure azure-storage azure-web-app-service

由于Azure 存储帐户上的静态网站功能不再处于预览模式,是否可以通过编程方式设置此选项(通过 Powershell Az 命令/Azure CLI)?

目前我能看到的唯一方法是在 UI 中手动执行:

在此处输入图片说明

Ana*_*tit 5

根据文档:

https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website

你可以使用 CLI

az storage blob service-properties update --account-name <ACCOUNT_NAME> --static-website --404-document <ERROR_DOCUMENT_NAME> --index-document <INDEX_DOCUMENT_NAME>
Run Code Online (Sandbox Code Playgroud)


Ern*_*dob 2

您可以使用blob存储rest api。用于设置blob服务属性的端点。从 2018-03-28 api 版本开始,您可以更改静态网站属性。

PUT https://<account-name>.blob.core.windows.net/?restype=service&comp=properties

身体:

<?xml version="1.0" encoding="utf-8"?>  
<StorageServiceProperties>  
    <StaticWebsite>
        <Enabled>true|false</Enabled>
        <IndexDocument>default-name-of-index-page-under-each-directory</IndexDocument>
        <ErrorDocument404Path>absolute-path-of-the-custom-404-page</ErrorDocument404Path>
    </StaticWebsite>
</StorageServiceProperties>  
Run Code Online (Sandbox Code Playgroud)

请参阅有关如何授权自己的文档。

https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties

Powershell 抽象存在。

Enable-AzStorageStaticWebsite -IndexDocument $indexdoc -ErrorDocument404Path $errordoc https://learn.microsoft.com/en-us/powershell/module/az.storage/enable-azstoragestaticwebsite?view=azps-1.3.0