how to export ssl key , crt and CA from httpd.conf apache to use it into nginx for all users

人走茶凉 提交于 2019-12-04 07:23:46

问题


use custom setup that use nginx as web engine with cpanel need command to export ssl files to use it into nginx

cpanel now use AutoSSL powered by Comodo that give it free and will renew it automatic when any users domains ssl expire

example httpd.conf

<VirtualHost 4xx30:4433>
  ServerName xnxxsch.com
  <IfModule ssl_module>
 SSLCertificateFile /var/cpanel/ssl/installed/certs/xnh_com_d98c5_67ca3_150707$
    SSLCertificateKeyFile /var/cpanel/ssl/installed/keys/d98c5_67ca3_76c14a301e0260891bbe91504$
    SSLCACertificateFile /var/cpanel/ssl/installed/cabundles/cPanel_Inc__681917bfb43af6b642178$
  </IfModule>
</VirtualHost>

<VirtualHost 46.xx30:4433>
  ServerName xxxh.com
  <IfModule ssl_module>
 SSLCertificateFile /var/cpanel/ssl/installed/certs/xnah_com_d98c5_67ca3_150707$
    SSLCertificateKeyFile /var/cpanel/ssl/installed/keys/d98c5_67ca3_76c14a301e0260891bbe91504$
    SSLCACertificateFile /var/cpanel/ssl/installed/cabundles/cPanel_Inc__681917bfb43af6b642178$
  </IfModule>
</VirtualHost>

need to export every domains (ServerName)

as two files

SSLCertificateKeyFile as ServerName.key

and

SSLCertificateFile+ SSLCACertificateFile as ServerName.crt

from ssh

with

grep 'ServerName' /etc/apache2/conf/httpd.conf

i export all need to use at loop

to get SSLCertificateKeyFile under it

and copy it with name servername.crt to /etc/nginx/ssl/


回答1:


I'm sure some efficiency nuts will choke on this, but it should work:

#!/bin/bash
# Look for ServerName, and extract the value.  Loop over results.
for server in $( grep ServerName httpd.conf | sed 's/.*ServerName\s*//' ); do
    echo $server
    # Pull out the block of XML for that server
    block=$( grep -A5 "$server" httpd.conf)

    # Extract file names from the XML block
    SSLCertificateFile=$( echo "$block" | sed -n 's/.*SSLCertificateFile\s*//p')
    SSLCertificateKeyFile=$( echo "$block" | sed -n 's/.*SSLCertificateKeyFile\s*//p')
    SSLCACertificateFile=$( echo "$block" | sed -n 's/.*SSLCACertificateFile\s*//p')

    # Create files
    cp "$SSLCertificateKeyFile" "${server}.key"
    cat "$SSLCertificateFile" "$SSLCACertificateFile" > "${server}.crt"
done
# end of loop


来源:https://stackoverflow.com/questions/44978623/how-to-export-ssl-key-crt-and-ca-from-httpd-conf-apache-to-use-it-into-nginx-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!