简体   繁体   English

如何在ubuntu的apache服务器中安装SSL证书

[英]How to install SSL certificate in apache server in ubuntu

I want enter localhost like a https://localhost , I need to do this with ssl.我想像https:// localhost 一样输入 localhost ,我需要用 ssl 来做到这一点。 How to install SSL certificate in apache server in ubuntu?如何在ubuntu的apache服务器中安装SSL证书?

Thanks in advance提前致谢

You have to add your certificate to your httpd.conf file in the VirtualHost section and change the port to 433. A Minimal config looks like this:您必须将您的证书添加到VirtualHost部分的httpd.conf文件中,并将端口更改为 433。最小配置如下所示:

LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost *:443>
    # maybe additional config here

    ServerName www.example.com

    SSLEngine on
    SSLCertificateFile "/path/to/www.example.com.cert"
    SSLCertificateKeyFile "/path/to/www.example.com.key"

</VirtualHost>

The httpd.conf should be in /etc/httpd , /etc/apache/ or similar. httpd.conf应该在/etc/httpd/etc/apache/或类似文件中。

Restart the server afterwards.之后重启服务器。

More information on Apache Server SSL .有关Apache 服务器 SSL 的更多信息。

Ubuntu doesn't use httpd.conf as standard, instead global configuration stuff for apache is found in /etc/apache2/apache2.conf . Ubuntu 不使用 httpd.conf 作为标准,而是在 /etc/apache2/apache2.conf 中找到了 apache 的全局配置内容。 You can create a httpd.conf in the apache2 directory, and load any further configuration from it by including the following line in /etc/apache2/apache2.conf.您可以在 apache2 目录中创建一个 httpd.conf,并通过在 /etc/apache2/apache2.conf 中包含以下行来从中加载任何进一步的配置。

The following steps are based on Ubuntu server with Apache2.以下步骤基于带有 Apache2 的 Ubuntu 服务器。 Step 1: Copy/paste your SSL certificate files to the server.步骤 1:将您的 SSL 证书文件复制/粘贴到服务器。

Download your Intermediate Certificate (CertificateAuthority.cert) and SSL Certificate (Example_Your_Domain.cert) from your Certificate Authority (such as Symantec, GeoTrust, RapidSSL or Thawte).从您的证书颁发机构(例如 Symantec、GeoTrust、RapidSSL 或 Thawte)下载您的中间证书 (CertificateAuthority.cert) 和 SSL 证书 (Example_Your_Domain.cert)。

Copy the Intermediate Certificate and SSL Certificate to the directory on the server where you will keep the certificate and key files.将中间证书和 SSL 证书复制到服务器上保存证书和密钥文件的目录。 Make them readable by root only.使它们只能由 root 读取。

Step 2: Locate the Apache configuration file to editing.步骤 2:找到要编辑的 Apache 配置文件。 Generally in Ubuntu's Apache the configuration file can be found in;一般在Ubuntu的Apache中可以找到配置文件; /etc/apache2/sites-enabled/example_your_domain /etc/apache2/sites-enabled/example_your_domain

Note: If you are unable to find the configuration file on the folder location “sites-enabled” then you must run the following command “sudo a2ensite example_your_domain” Open the configuration file with a text editor and locate blocks that contain Apache setting.注意:如果您无法在文件夹位置“sites-enabled”上找到配置文件,那么您必须运行以下命令“sudo a2ensite example_your_domain”使用文本编辑器打开配置文件并找到包含 Apache 设置的块。

Step 3: Find the SSL block to configure.第 3 步:找到要配置的 SSL 块。 If your intention to access your website using both “https” and “http” connections, then you need two separate files in /etc/apache2/sites-enabled/.如果您打算同时使用“https”和“http”连接访问您的网站,那么您需要 /etc/apache2/sites-enabled/ 中的两个单独文件。 One is for port 80 and another for port 443.一个用于端口 80,另一个用于端口 443。

Step 4: Configure the block for the “SSL-enabled” website.步骤 4:为“启用 SSL”的网站配置块。 Here is an example of a virtual host configured for SSL certificate connection.这是为 SSL 证书连接配置的虚拟主机的示例。 The parts in bold letters must be configured to established secure connection of HTTPS on Ubuntu Server with Apache2粗体部分必须配置为在Ubuntu Server上与Apache2建立HTTPS的安全连接

DocumentRoot /var/www/ 
SSLEngine on 
SSLCertificateFile /path/to/example _your _domain.crt 
SSLCertificateKeyFile /path/to/your_private.key 
SSLCertificateChainFile /path/to/CertificateAuthority.crt

Make your file names match your certificate files, such as;使您的文件名与您的证书文件相匹配,例如; SSLCertificateFile is your certificate file (eg. example_your_domain.crt). SSLCertificateFile 是您的证书文件(例如 example_your_domain.crt)。 SSLCertificateKeyFile is your key file that you generated while creation of the CSR. SSLCertificateKeyFile 是您在创建 CSR 时生成的密钥文件。 SSLCertificateChainFile is the Certificate Authority intermediate certificate file (Symantec.crt) SSLCertificateChainFile 是证书颁发机构中间证书文件 (Symantec.crt)

Step 5: That's it!第5步:就是这样! Restart Apache Now!立即重启 Apache!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM