Can access be provided to a static website stored in a private azure storage container?

Lilly, Michael 0 Reputation points
2023-08-31T18:04:42.4333333+00:00

I am trying to render a static web site stores in an private azure blob container utilizing a SAS URL.

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,200 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Konstantinos Passadis 19,591 Reputation points MVP
    2023-09-02T10:44:41.46+00:00

    Hello @Lilly, Michael !

    Welcome to Microsoft QnA!

    Usually Azure Storage provides Web Static Hosting on Public storage

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

    If you want to render a static website stored in a private Azure Blob container using a SAS (Shared Access Signature) URL, you can try this :

    First of al allow Anonymous Access , otherwise it would never work

    User's image

    Set Up Your Blob Container:

    • Make sure you've set up a blob container in Azure Blob Storage and that it's configured for private access so that the blobs can't be accessed without appropriate authorization.

    Upload Your Static Website:

    • Upload the content of your static website (e.g., index.html, styles.css, script.js, etc.) to the blob container.
    1. Generate a SAS URL:

    Use Azure Portal, Azure CLI, or one of the Azure SDKs to generate a SAS URL for your blob container.

    • Azure CLI Example:
    1. az storage blob generate-sas --account-name <YourStorageAccountName> --container-name <YourContainerName> --name <BlobName> --permissions r --expiry <ExpiryDateTime> --type object
    2. Accessing the Static Website Using SAS URL:

    Construct the URL for accessing the static website:

    1. https://<YourStorageAccountName>.blob.core.windows.net/<YourContainerName>/<BlobName>?<GeneratedSAS>
      • Replace <YourStorageAccountName>, <YourContainerName>, <BlobName>, and <GeneratedSAS> with appropriate values.
           - For the root of your website, `<BlobName>` will likely be `index.html` or similar.
        

    ALSO : Any internal references for example from index.html to style.css must be with relevant SAS for each file ! It wont work otherwise!

    Here is my Index.html referencing style.css

    <!DOCTYPE html>
    <html>
    <head>
        <title>My App</title>
        <link rel="stylesheet" href="https://srtgggsq.blob.core.windows.net/web/style.css?sp=r&st=2023-09-02T10:56:41Z&se=2023-09-02T18:56:41Z&spr=https&sv=2022-11-02&sr=b&sig=qKxGF8iRYpesdmV5e4tvuOwkAJ4DG2nSvB4MVcz6rUI%3D"/>
    </head>
    <body>
        <div class="container">
    

    I have tried this and it have worked so please send us your input

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    Regards

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.