设为首页 收藏本站
查看: 572|回复: 0

[经验分享] How To Create a SSL Certificate on Apache for Debian 8 htttps

[复制链接]

尚未签到

发表于 2018-11-20 10:09:18 | 显示全部楼层 |阅读模式
  June 19, 2015  Security, Apache Debian
Introduction
  This tutorial walks you through the setup and configuration of an
Apache server secured with an SSL certificate. By the end of the
tutorial, you will have a server accessible via HTTPS.
  SSL is based on the mathematical intractability of resolving a large
integer into its also-large prime factors. Using this, we can encrypt
information using a private-public key pair. Certificate authorities canissue SSL certificates that verify the authenticity of such a secured
connection, and on the same note, a self-signed certificate can be
produced without third-party support.
  In this tutorial, we will generate a self-signed certificate, make
the necessary configurations, and test the results. Self-signed
certificates are great for testing, but will result in browser errors
for your users, so they're not recommended for production.
  If you'd like to obtain a paid certificate instead, please see this tutorial.
Prerequisites
  To follow this tutorial, you will need:

  •   One fresh Debian 8 Droplet
  •   A sudo non-root user, which you can set up by following Steps 2 and 3 of this tutorial
  •   OpenSSL installed and updated (should be installed by default)
sudo apt-get updatesudo apt-get upgrade openssl  You may want a second computer with OpenSSL installed, for testing purposes:

  •   Another Linux Droplet
  •   Or, a Unix-based local system (Mac, Ubuntu, Debian, etc.)
Step 1 — Install Apache
  In this step, we will use a built-in package installer called apt-get. It simplifies package management drastically and facilitates a clean installation.
  In the link specified in the prerequisites, you should have updated apt-get and installed the sudo package, as unlike other Linux distributions, Debian 8 does not come with sudo installed.
  Apache will be our HTTPS server. To install it, run the following:
sudo apt-get install apache2Step 2 — Enable the SSL Module
  In this section, we will enable SSL on our server.
  First, enable the Apache SSL module.
sudo a2enmod ssl  The default Apache website comes with a useful template for enabling SSL, so we will activate the default website now.
sudo a2ensite default-ssl  Restart Apache to put these changes into effect.
sudo service apache2 reloadStep 3 — Create a Self-Signed SSL Certificate
  First, let's create a new directory where we can store the private key and certificate.
sudo mkdir /etc/apache2/ssl  Next, we will request a new certificate and sign it.
  First, generate a new certificate and a private key to protect it.

  •   The days flag specifies how long the certificate should remain valid. With this example, the certificate will last for one year
  •   The keyout flag specifies the path to our generated key
  •   The out flag specifies the path to our generated certificate
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt  Invoking this command will result in a series of prompts.

  •   Common Name: Specify your server's IP address or
    hostname. This field matters, since your certificate needs to match the
    domain (or IP address) for your website
  •   Fill out all other fields at your own discretion.
  Example answers are shown in red below.
InteractiveYou are about to be asked to enter information that will be incorporated  
into your certificate request.
  
What you are about to enter is what is called a Distinguished Name or a DN.
  
There are quite a few fields but you can leave some blank
  
For some fields there will be a default value,
  
If you enter '.', the field will be left blank.
  
——-
  
Country Name (2 letter code) [AU]:USState or Province Name (full name) [Some-State]:New YorkLocality Name (eg, city) []:NYCOrganization Name (eg, company) [Internet Widgits Pty Ltd]:DigitalOceanOrganizational Unit Name (eg, section) []:SSL Certificate TestCommon Name (e.g. server FQDN or YOUR name) []:example.com               Email Address []:test@example.com
  Set the file permissions to protect your private key and certificate.
sudo chmod 600 /etc/apache2/ssl/*  For more information on the three-digit permissions code, see the tutorial on Linux permissions.
  Your certificate and the private key that protects it are now ready for Apache to use.
Step 4 — Configure Apache to Use SSL
  debian的ssl配置文件在这里
root@uat:~# vim /etc/apache2/sites-available/default-ssl.conf  In this section, we will configure the default Apache virtual host touse the SSL key and certificate. After making this change, our server
will begin serving HTTPS instead of HTTP requests for the default site.
  Open the server configuration file using nano or your favorite text editor.
sudo nano /etc/apache2/sites-enabled/default-ssl.conf  Locate the section that begins with  and make the following changes.

  •   Add a line with your server name directy below the ServerAdmin email line. This can be your domain name or IP address:
  /etc/apache2/sites-enabled/default
ServerAdmin webmaster@localhost  
ServerName example.com:443

  •   Find the following two lines, and update the paths to match the
    locations of the certificate and key we generated earlier. If you
    purchased a certificate or generated your certificate elsewhere, make
    sure the paths here match the actual locations of your certificate and
    key:
  /etc/apache2/sites-enabled/default
SSLCertificateFile /etc/apache2/ssl/apache.crt  
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
  Once these changes have been made, check that your virtual host configuration file matches the following.
  /etc/apache2/sites-enabled/default-ssl
  
   
  
        ServerAdmin webmaster@localhost
  
        ServerName example.com:443
  
        DocumentRoot /var/www/html
  

  
        . . .
  
        SSLEngine on
  

  
        . . .
  

  
        SSLCertificateFile /etc/apache2/ssl/apache.crt
  
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
  Save and exit the file.
  Restart Apache to apply the changes.
sudo service apache2 reload  To learn more about configuring Apache virtual hosts in general, see this article.
Step 5 — Test Apache with SSL
  In this section, we will test your SSL connection from the command line.
  You can run this test from either (1) your local Unix-based system,
(2) another Droplet, or (3) the same Droplet. If you run it from an
external system you'll confirm that your site is reachable over the
public Internet.
  Open a connection via the HTTPS 443 port.
openssl s_client -connect your_server_ip:443  Scroll to the middle of the output (after the key), and you should find the following:
Output—-  
SSL handshake has read 3999 bytes and written 444 bytes
  
—-
  

  
. . .
  

  
SSL-Session:
  

  
. . .
  Of course, the numbers are variable, but this is success. Congratulations!
  Press CTRL+C to exit.
  You can also visit your site in a web browser, using HTTPS in the URL (https://example.com).Your browser will warn you that the certificate is self-signed. You
should be able to view the certificate and confirm that the details
match what you entered in Step 3.
Conclusion
  This concludes our tutorial, leaving you with a working Apache
server, configured securely with an SSL certificate. For more
information on working with OpenSSL, see the OpenSSL Essentials article.



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-637266-1-1.html 上篇帖子: apache编译出错 error: mod_deflate has been requested 下篇帖子: How To Create a SSL Certificate on Apache for Debian 7 |htttps
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表