USE HTTPS in C# by Running the Container with a Certificate

This article was translated from English: Does it need improvement?
Translated
View the article in English

若需使用憑證執行容器,請依照以下步驟產生憑證並設定本地端機器:

使用憑證執行 IronSecureDoc 容器

  1. 產生憑證

    # Generates a new HTTPS certificate for use with ASP.NET Core.
    # Saves the certificate at the specified path and protects it with a password.
    dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>
    
    # Trusts the generated certificate on your local machine.
    dotnet dev-certs https --trust
    # Generates a new HTTPS certificate for use with ASP.NET Core.
    # Saves the certificate at the specified path and protects it with a password.
    dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>
    
    # Trusts the generated certificate on your local machine.
    dotnet dev-certs https --trust
    SHELL

    請將 <CREDENTIAL_PLACEHOLDER> 替換為密碼。

  2. 執行 Docker 容器

    # Runs the IronSecureDoc Docker container with both HTTP and HTTPS ports exposed.
    docker container run -d \
     -p 8081:8081 -p 8080:8080 \ # Maps container ports to host ports for HTTP and HTTPS.
     -e HTTP_PORTS=8080 \ # Sets the HTTP port for the application.
     -e HTTPS_PORTS=8081 \ # Sets the HTTPS port for the application.
     -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \ # Provides the IronSecureDoc license key.
     -e ENVIRONMENT=Production \ # Configures the environment as Production.
     -v %USERPROFILE%\.aspnet\https:/https:ro \ # Mounts the directory to the container as read-only.
     -e CERTIFICATE_PATH=%USERPROFILE%\.aspnet\https\ironsecuredoc.pfx \ # Specifies the path to the certificate in the container.
     -e CERTIFICATE_PASSWORD=<CERTIFICATE_PASSWORD> \ # Password for the certificate.
     ironsoftwareofficial/ironsecuredoc:latest # Specifies the Docker image to use.
    # Runs the IronSecureDoc Docker container with both HTTP and HTTPS ports exposed.
    docker container run -d \
     -p 8081:8081 -p 8080:8080 \ # Maps container ports to host ports for HTTP and HTTPS.
     -e HTTP_PORTS=8080 \ # Sets the HTTP port for the application.
     -e HTTPS_PORTS=8081 \ # Sets the HTTPS port for the application.
     -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \ # Provides the IronSecureDoc license key.
     -e ENVIRONMENT=Production \ # Configures the environment as Production.
     -v %USERPROFILE%\.aspnet\https:/https:ro \ # Mounts the directory to the container as read-only.
     -e CERTIFICATE_PATH=%USERPROFILE%\.aspnet\https\ironsecuredoc.pfx \ # Specifies the path to the certificate in the container.
     -e CERTIFICATE_PASSWORD=<CERTIFICATE_PASSWORD> \ # Password for the certificate.
     ironsoftwareofficial/ironsecuredoc:latest # Specifies the Docker image to use.
    SHELL

    請分別將 <IRONSECUREDOC_LICENSE_KEY><CERTIFICATE_PASSWORD> 替換為您實際的 IronSecureDoc 授權金鑰和憑證密碼。

常見問題

HTTPS 為何對文件安全性至關重要?

HTTPS 對於文件安全性至關重要,因為它會對傳輸中的資料進行加密,確保敏感資訊在傳輸過程中保持機密性,並防止遭竊聽。

我該如何為我的應用程式建立 HTTPS 憑證?

您可以透過執行指令 `dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\IronSecureDoc.pfx -p` 來建立 HTTPS 憑證,此指令會產生一個可用於 .NET Core 的新憑證。

如何確保我的 HTTPS 憑證在本地電腦上受到信任?

若要在本地電腦上信任您的 HTTPS 憑證,請使用命令 dotnet dev-certs https --trust。此命令會將系統設定為信任所產生的憑證。

如何執行支援 HTTPS 的 Docker 容器?

若要執行支援 HTTPS 的 Docker 容器,請同時開放 HTTP 和 HTTPS 連接埠,設定必要的環境變數(例如 IronSecureDoc_LicenseKeyCERTIFICATE_PASSWORD),並將憑證目錄掛載為唯讀。

在 Docker 環境中,HTTPS 應配置哪些埠號?

在 Docker 環境中進行 HTTPS 設定時,請將容器埠號映射至主機埠號,具體方式為:將 8081 埠用於 HTTPS,8080 埠用於 HTTP。

如何將憑證密碼傳遞給 Docker 容器?

執行 Docker run 指令時,請透過環境變數 CERTIFICATE_PASSWORD 將憑證密碼傳遞給 Docker 容器。

在 Docker 中將環境設定為「生產環境」需要哪些步驟?

若要在 Docker 中將環境設定為「Production」,請在 Docker 執行指令中設定環境變數 ENVIRONMENT=Production

在 Docker 指令中應如何處理佔位符?

在 Docker 指令中,請將 等佔位符替換為您的實際 IronSecureDoc 授權金鑰和憑證密碼,以確保功能正常運作。

Curtis Chau
技術撰稿人

Curtis Chau 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備開始了嗎?
版本: 2024.10 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎?
執行範例 觀看您的 PDF 被加密。