在 C# 中使用 HTTPS,方法是使用憑證執行容器。
如果需要使用憑證執行容器,請依照下列步驟產生憑證並設定本機:
使用憑證運行 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代替<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.代替<IRONSECUREDOC_LICENSE_KEY>和<CERTIFICATE_PASSWORD>分別使用您的 IronSecureDoc 授權金鑰和憑證密碼。
常見問題解答
為什麼 HTTPS 對文件安全很重要?
HTTPS 對於文件安全至關重要,因為它會加密傳輸的數據,確保敏感信息在傳輸過程中保持機密並受到保護免受攔截。
如何為我的應用程序創建 HTTPS 證書?
您可以通過運行命令 dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER> 來創建 HTTPS 證書,這會生成一個用於 ASP.NET Core 的新證書。
如何確保我的本地計算機信任我的 HTTPS 證書?
要讓您的本地計算機信任您的 HTTPS 證書,請使用命令 dotnet dev-certs https --trust。此命令會配置您的系統以信任生成的證書。
運行支援 HTTPS 的 Docker 容器的過程是什麼?
要運行支援 HTTPS 的 Docker 容器,請暴露 HTTP 和 HTTPS 端口,設置必要的環境變量,如 IronSecureDoc_LicenseKey 和 CERTIFICATE_PASSWORD,並將證書目錄掛載為唯讀。
在 Docker 配置中應該配置哪些端口以支援 HTTPS?
在 Docker 配置中為 HTTPS 配置端口,將容器端口映射到主機端口,暴露 8081 端口給 HTTPS 和 8080 端口給 HTTP。
如何將證書密碼傳遞給 Docker 容器?
在執行 Docker 運行命令時,使用環境變量 CERTIFICATE_PASSWORD 將證書密碼傳遞給 Docker 容器。
要將環境配置為 Docker 中的「生產環境」需要哪些步驟?
要將環境配置為 Docker 中的「生產環境」,請在你的 Docker 運行命令中設置環境變量 ENVIRONMENT=Production。
如何在 Docker 命令中處理佔位符?
在 Docker 命令中,將佔位符如 <IRONSECUREDOC_LICENSE_KEY> 和 <CERTIFICATE_PASSWORD> 替換為您實際的 IronSecureDoc 授權密鑰和證書密碼,以確保正常功能。





