【问题标题】:HTTPS access to Azure ubuntu Virtual Machine对 Azure ubuntu 虚拟机的 HTTPS 访问
【发布时间】:2018-12-17 01:24:58
【问题描述】:

我有一个在 Microsoft azure 上运行的 Ubuntu VM。 目前我可以使用 HTTP 访问它,但不能使用 HTTPS。 在网络接口,入站端口规则,443已经被允许了。

我已经在虚拟机中添加了一个证书,通过创建一个密钥库和一个证书,准备按照this documentation进行部署:

az keyvault update -n <keyvaultname> -g <resourcegroupname> --set properties.enabledForDeployment=true

然后在this answer 之后添加证书。

在 Azure CLI 中:

$secret=$(az keyvault secret list-versions \
          --vault-name <keyvaultname> \
          --name <certname> \
          --query "[?attributes.enabled].id" --output tsv)
$vm_secret=$(az vm secret format --secret "$secret")

az vm update -n <vmname> -g <keyvaultname> --set osProfile.secrets="$vm_secret"

我收到以下错误:

Unable to build a model: Cannot deserialize as [VaultSecretGroup] an object of type <class 'str'>, DeserializationError: Cannot deserialize as [VaultSecretGroup] an object of type <class 'str'>

但是,当我在那之后az vm show -g &lt;resourcegroupname&gt; -n &lt;vmname&gt; 时,在osProfile 中,秘密已经包含了我添加的秘密

"secrets": [
      {
        "sourceVault": {
          "id": "/subscriptions/<subsID>/resourceGroups/<resourcegroupName>/providers/Microsoft.KeyVault/vaults/sit-key-vault"
        },
        "vaultCertificates": [
          {
            "certificateStore": null,
            "certificateUrl": "https://<keyvaultname>.vault.azure.net/secrets/<certname>/<certhash>"
          }
        ]
      }
    ],

使用 HTTPS 访问时,我失败了。我可以使用 HTTP 访问它,但 chrome 仍然在地址旁边显示“不安全”标记。

我错过了什么?

我也检查了answer from similar question,但在虚拟机控制面板页面的任何地方都找不到“启用直接服务器返回”。

【问题讨论】:

  • 您可以在带有 bash 环境的 Azure Cloud Shell 中执行此操作。当vm_secret 是字符串类型时,它可以正常工作。

标签: azure ssl https


【解决方案1】:

据我所知,我们可以按照以下步骤为 nginx 服务器配置 SSL。

  1. 添加 SSL 证书

    $secret=$(az keyvault secret list-versions --vault-name "keyvault_name" --name "cert name" --query "[?attributes.enabled].id" --output tsv)

    $vm_secret=$(az vm 密钥格式 --secrets "$secret")

    az vm update -n “虚拟机名称” -g “资源组名称” --set osProfile.secrets="$vm_secret"

  2. 安装 Nginx

    sudo apt-get 更新

    sudo apt-get install nginx

  3. 配置 SSL 证书

     #get cert name
     find /var/lib/waagent/ -name "*.prv" | cut -c -57
    
     #paste cert
     mkdir /etc/nginx/ssl
     cp “your cert name” /etc/nginx/ssl/mycert.cer
     cp “your cert name” /etc/nginx/ssl/mycert.prv
    
     #change nginx configuration file
     sudo nano /etc/nginx/sites-available/default
     PS: add the next content in the file
     server {
        listen 443 ssl;
        ssl_certificate /etc/nginx/ssl/mycert.cert;
        ssl_certificate_key /etc/nginx/ssl/mycert.prv;
               }
      service nginx restart
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    相关资源
    最近更新 更多