在Apache中,如何为其他端口设置SSL证书?

分享于 

3分钟阅读

ubuntu

  繁體

在apache中进行修改,/etc/apache2/ports.conf通知apache监听端口:


Listen 8080


<IfModule ssl_module> 


 Listen 446


</IfModule>



步骤如下:

  • 创建你的SSL证书:

    • 生成目录以添加证书:

      
      mkdir -p /etc/apache2/ssl/example.com
      
      
      
      
    • 创建自签名证书:

      
      sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/example.com/apache.key -out /etc/apache2/ssl/example.com/apache.crt
      
      
      
      
  • 使用以下命令启用ssl模块:sudo a2enmod ssl

  • Virtualhost文件中创建条目(已调用example.conf ) sudo nano /etc/apache2/sites-available/example.conf

    
    <VirtualHost *:8080>
    
    
     ServerAdmin webmaster@localhost
    
    
     ServerName example.com
    
    
     DocumentRoot /var/www/html
    
    
    
    </VirtualHost>
    
    
    
    <IfModule mod_ssl.c>
    
    
    <VirtualHost *:446>
    
    
    
     ServerAdmin webmaster@localhost
    
    
     ServerName example.com
    
    
     DocumentRoot /var/www/html
    
    
    
     # SSL Engine Switch:
    
    
     # Enable/Disable SSL for this virtual host.
    
    
     SSLEngine on
    
    
    
     # A self-signed (snakeoil) certificate can be created by installing
    
    
     # the ssl-cert package. See
    
    
     # /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
    
    
     # If both key and certificate are stored in the same file, only the
    
    
     # SSLCertificateFile directive is needed.
    
    
     SSLCertificateFile /etc/apache2/ssl/example.com/apache.crt
    
    
     SSLCertificateKeyFile /etc/apache2/ssl/example.com/apache.key
    
    
    </VirtualHost>
    
    
    
    </IfModule>
    
    
    
    
  • 通过将端口添加到/etc/apache2/ports.conf文件,让apache侦听新端口:

    
    Listen 8080
    
    
    <IfModule ssl_module> 
    
    
     Listen 446
    
    
    </IfModule>
    
    
    
    <IfModule mod_gnutls.c>
    
    
     Listen 446
    
    
    </IfModule>
    
    
    
    
  • 启用配置文件:

    
    sudo a2ensite example
    
    
    
    
  • 重新启动apache:

    
    sudo systemctl restart apache2
    
    
    
    


  • Server  添加  SET  Apache  加法  SSL  
    相关文章