ubuntu14.04安装apache2.4,启动ssl

ubuntu14.04安装apache2.4,启动ssl

时间: 2015-02-28 21:37
作者: lsgxeva
分类:  我的笔记>>web>> a pache
摘要:  ubuntu14.04安装apache2.4,启动ssl
标签:  ubuntu  apache ssl
提示: 文章均来自网络,版权为原作者所有,如有侵犯权益,请联络我们.



ubuntu14.04安装apache2.4,启动ssl

  • Server
  • 发表于 3个月前 (05-08)
  • 119384 次浏览
  • 暂无评论
A A A

由于我的apache只是整合svn用,所以端口有改变,并非使用80和443端口。

apache使用的是2.4版本,ppa源的。

  1. 安装输入命令:
           
           
           
           
    apt - get install apache2
    • 提示:
               
               
               
               
      正在读取软件包列表... 完成
      正在分析软件包的依赖关系树
      正在读取状态信息... 完成
      将会安装下列额外的软件包:
      apache2 - bin apache2 - data apache2 - utils libapr1 libaprutil1
      libaprutil1 - dbd - sqlite3 libaprutil1 - ldap liblua5 . 1 - 0 ssl - cert
      建议安装的软件包:
      apache2 - doc apache2 - suexec - pristine apache2 - suexec - custom openssl - blacklist
      下列【新】软件包将被安装:
      apache2 apache2 - bin apache2 - data apache2 - utils libapr1 libaprutil1
      libaprutil1 - dbd - sqlite3 libaprutil1 - ldap liblua5 . 1 - 0 ssl - cert
      升级了 0 个软件包,新安装了 10 个软件包,要卸载 0 个软件包,有 5 个软件包未被升级。
      需要下载 1 , 712 kB 的软件包。
      解压缩后会消耗掉 6 , 273 kB 的额外空间。
      您希望继续执行吗? [ Y / n ]
    • 确定安装,输入:
               
               
               
               
      y
    • 安装成功提示:
               
               
               
               
      Enabling site 000 - default .
      * Starting web server apache2
      AH00558 : apache2 : Could not reliably determine the server 's fully qualified domain name, using 127.0.1.1. Set the ' ServerName ' directive globally to suppress this message
      *
      正在设置 ssl-cert (1.0.33) ...
      正在处理用于 libc-bin (2.19-0ubuntu6.6) 的触发器 ...
      正在处理用于 ureadahead (0.100.0-16) 的触发器 ...
  2. 安装成功后修改配置文件,进入:
           
           
           
           
    /etc/ apache2 / sites - enabled
    • 首先添加一个SSL的配置文件:
               
               
               
               
      default - ssl . conf
      • 复制
                   
                   
                   
                   
        000 - default . conf
      •            
                   
                   
                   
        /etc/ apache2 / sites - enabled
      • 并改名为
                   
                   
                   
                   
        default - ssl . conf
      • 修改连接为
                   
                   
                   
                   
        ../ sites - available / default - ssl . conf
    • 修改配置文件:
               
               
               
               
      000 - default . conf
      • 由于80端口用于nginx,所以apache使用80以外的端口。
        • 修改第1行的:
                       
                       
                       
                       
          <VirtualHost *:80 >
        • 为80以外的端口:
                       
                       
                       
                       
          <VirtualHost *:9080 >
      • 修改第11行的:
                   
                   
                   
                   
        ServerAdmin webmaster@localhost
      • 为管理员的邮箱:
                   
                   
                   
                   
        ServerAdmin hxgsn@hxgsn . com
      • 第12行是指定虚拟主机的根目录:
                   
                   
                   
                   
        DocumentRoot   / var / www / html
    • 我需要使用ssl,修改SSL配置文件:
               
               
               
               
      default - ssl . conf
      • 同样443端口nginx在使用,所以修改成别的端口。
        • 修改第2行的:
                       
                       
                       
                       
          <VirtualHost _ default_:443 >
        • 为443以外的端口:
                       
                       
                       
                       
          <VirtualHost _ default_:9443 >
      • 修改第3行的:
                   
                   
                   
                   
        ServerAdmin webmaster@localhost
      • 为管理员的邮箱:
                   
                   
                   
                   
        ServerAdmin hxgsn@hxgsn . com
      • 第5行是指定虚拟主机的根目录:
                   
                   
                   
                   
        DocumentRoot   / var / www / html
      • 使用ssl需要使用证书,我是穷孩子,所以我去wosign申请了免费证书。
        • 安装apache时候生成:
                       
                       
                       
                       
          ssl - cert - snakeoil . pem
                       
                       
                       
                       
          ssl - cert - snakeoil . key
        • wosign生成的是:
                       
                       
                       
                       
          server - ca . crt
                       
                       
                       
                       
          ca - bundle . crt
        • 第32行:
                       
                       
                       
                       
          SSLCertificateFile / etc / ssl / certs / ssl - cert - snakeoil . pem
        • 第33行:
                       
                       
                       
                       
          SSLCertificateKeyFile / etc / ssl / private / ssl - cert - snakeoil . key
        • 第42行:
                       
                       
                       
                       
          #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt
          • 去掉:
                           
                           
                           
                           
            #
          • 修改为:
                           
                           
                           
                           
            SSLCertificateChainFile / etc / apache2 / ssl . crt / server - ca . crt
        • 第52行:
                       
                       
                       
                       
          #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt
          • 去掉:
                           
                           
                           
                           
            #
          • 修改为:
                           
                           
                           
                           
            SSLCACertificateFile / etc / apache2 / ssl . crt / ca - bundle . crt
      • 打开目录:
                   
                   
                   
                   
        /etc/ apache2
        • 新建用于存放证书的目录
                       
                       
                       
                       
          ssl . crl
      • 解压wosign提供证书包:
                   
                   
                   
                   
        hxgsn . com_sha256_cn
        • 里面提供了5个压缩包,解压:
                       
                       
                       
                       
          for Apache . zip
          • 里面有3个文件:
            • 根证书:
                               
                               
                               
                               
              1 _root_bundle . crt
              • 对应为:
                                   
                                   
                                   
                                   
                SSLCertificateChainFile
                • 修改根证书名字为:
                                       
                                       
                                       
                                       
                  server - ca . crt
                • 上传到:
                                       
                                       
                                       
                                       
                  /etc/ apache2 / ssl . crt
                • 也可以在:
                                       
                                       
                                       
                                       
                  default - ssl . conf
                • 修改为对应的文件名。
            • 域名证书:
                               
                               
                               
                               
              2 _hxgsn . com . crt
              • 对应为:
                                   
                                   
                                   
                                   
                SSLCACertificateFile
                • 修改域名证书名字为:
                                       
                                       
                                       
                                       
                  ca - bundle . crt
                • 上传到:
                                       
                                       
                                       
                                       
                  /etc/ apache2 / ssl . crt
                • 也可以在:
                                       
                                       
                                       
                                       
                  default - ssl . conf
                • 修改为对应的文件名。
            • 私钥:
                               
                               
                               
                               
              3 _hxgsn . com . key
              • 对应为:
                                   
                                   
                                   
                                   
                SSLCertificateKeyFile
                • 在安装apache2.4的时候会默认在
                                       
                                       
                                       
                                       
                  /etc/ ssl / private
                • 生成一个私钥:
                                       
                                       
                                       
                                       
                  ssl - cert - snakeoil . key
                • 修改私钥名字为:
                                       
                                       
                                       
                                       
                  ssl - cert - snakeoil . key
                • 上传到目录:
                                       
                                       
                                       
                                       
                  /etc/ ssl / private
                • 替换掉apache2.4生成的私钥。
                • 或者用记事本类的工具编辑
                                       
                                       
                                       
                                       
                  /etc/ ssl / private / ssl - cert - snakeoil . key
                • 把里面的内容替换成
                                       
                                       
                                       
                                       
                  3 _hxgsn . com . key
                • 里面的内容。
      • 安装apache2.4是除了生成私钥:
                   
                   
                   
                   
        ssl - cert - snakeoil . key
        • 还会在:
                       
                       
                       
                       
          /etc/ ssl / certs
        • 生成公钥:
                       
                       
                       
                       
          ssl - cert - snakeoil . pem
          • 对应为:
                           
                           
                           
                           
            SSLCertificateFile
          • 在wosign的用户中心可以找到证书公钥,把证书公钥存为文件:
                           
                           
                           
                           
            ssl - cert - snakeoil . pem
          • 上传到目录:
                           
                           
                           
                           
            /etc/ ssl / certs
          • 替换掉apache2.4生成的公钥
          • 或者用记事本类的工具编辑
                           
                           
                           
                           
            /etc/ ssl / certs / ssl - cert - snakeoil . pem
          • 把里面的内容替换成wosign用户中心的证书公钥内容。
  3. 修改目端口监听配置文件:
           
           
           
           
    etc / apache2 / ports . conf
    • 第5行:
               
               
               
               
      Listen 80
      • 指的是监听端口:
                   
                   
                   
                   
        80
      • 由于在
                   
                   
                   
                   
        000 - default . conf
      • 修改了默认端口,所以这里也修改成对应端口:
                   
                   
                   
                   
        Listen 9080
      • 第8行和第12行:
                   
                   
                   
                   
        Listen 443
      • 指的是监听端口:
                   
                   
                   
                   
        443
      • 由于在
                   
                   
                   
                   
        default - ssl . conf
      • 修改了默认端口,所以这里也修改成对应端口:
                   
                   
                   
                   
        Listen 9443
  4. 启动apache对ssl的支持,输入命令:
           
           
           
           
    a2enmod ssl
    • 启动成功提示:
               
               
               
               
      Enabling module socache_shmcb .
      Enabling module ssl .
      See / usr / share / doc / apache2 / README . Debian . gz on how to configure SSL and create self - signed certificates .
      To activate the new configuration , you need to run :
      service apache2 restart
    • 重启apache后ssl才会生效,输入命令:
               
               
               
               
      service apache2 restart
      • 重启成功提示:
                   
                   
                   
                   
        * Restarting web server apache2
        AH00558 : apache2 : Could not reliably determine the server 's fully qualified domain name, using 127.0.1.1. Set the ' ServerName ' directive globally to suppress this message [ OK ]
  5. apache的配置可以很灵活,这篇内容只是我的实战习惯了。




来自为知笔记(Wiz)


你可能感兴趣的:(ubuntu14.04安装apache2.4,启动ssl)