zoukankan      html  css  js  c++  java
  • Apache配置HTTPS功能

    apache配置https

    一、yum 安装openssl和openssl-devel,httpd-devel
    二、生成证书(也可以从公司的证书颁发机构获取):
    #建立服务器密钥  
    openssl genrsa -des3 1024  > /usr/local/apache/conf/server.key   
    # 从密钥中删除密码(以避免系统启动后被询问口令) 
    openssl rsa -in /usr/local/apache/conf/server.key > /usr/local/apache/conf/server2.key
    mv /usr/local/apache/conf/server2.key  /usr/local/apache/conf/server.key
    #建立服务器密钥请求文件
    openssl req -new -key /usr/local/apache/conf/server.key -out /usr/local/apache/conf/server.csr
    5>openssl x509 -in /usr/local/apache/conf/server.csr -out
    # 建立服务器证书  
    /usr/local/apache/conf/server.crt -req -signkey /usr/local/apache/conf/server.key -days 365
    
    三、修改Apache的配置文件httpd.conf

    打开ssl模块,没有这个模块就需要安装依赖包:mod_ssl,安装后就会在modules里面找到:

    LoadModule ssl_module         modules/mod_ssl.so
    

    引入ssl配置文件,增加支持ssl:

    Include conf/extra/httpd-ssl.conf(去掉行首的注释)
    
    • 启动重定向(可选),使用用户HTTP访问自动重定向为HTTPS,直接在http.conf最后配置即可,在httpd.conf文件尾加入如下内容:
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
    
    四、修改加密文件ssl.conf,通过yum安装好的httpd,在conf.d目录下面有ssl.conf配置文件,我们需要在里面配置一个VirtualHost和配置证书和密钥:
    LoadModule ssl_module modules/mod_ssl.so
    Listen 443
    SSLPassPhraseDialog  builtin
    SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
    SSLSessionCacheTimeout  300
    SSLMutex default
    SSLRandomSeed startup file:/dev/urandom  256
    SSLRandomSeed connect builtin
    SSLCryptoDevice builtin
    SSLProtocol all -SSLv2 -SSLv3
    SSLHonorCipherOrder on
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4:
    
    <VirtualHost _default_:443>     # 必须有一个虚拟主机,这样才可以使用跳转功能和使用443端口访问
    DocumentRoot "/home/store/webroot"
    Servername https://xxx.com/
    ErrorLog logs/ssl_error_log
    TransferLog logs/ssl_access_log
    LogLevel warn
    SSLEngine on
    SSLCertificateFile /etc/httpd/conf/cert/xxx.com.crt
    SSLCertificateKeyFile /etc/httpd/conf/cert/xxx.com.key
    </VirtualHost>
    
    
    五、重启Apache

    service httpd restart

    1. 在浏览器输入https://域名 或者 域名:443,如果两个能正常访问,表示https已经配置成功。
    2. 在浏览器输入 域名,如果能够正常跳转到https连接上,那说明跳转功能正常。
    • 启动apache 碰到下面问题:
    Invalid command 'SSLPassPhraseDialog', perhaps misspelled or defined by a module not included in the server configuration
    

    到apache的bin 目录下面执行 ./httpd -l 看看有没有mode_ssl.c,这个错误说明ssl模块安装没有成功。
    解决办法:

    • 1、重新编译apache,加上--enable-ssl --with-ssl参数

    • 2、把ssl模块加入到已经编译好的apache中
      首先,使用 whereis openssl 命令获取lib和include的路径

    [root@robot /usr/local/apache/modules]# whereis openssl
    openssl: /usr/bin/openssl /usr/lib/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz
    

    然后 在apache 源码的modules/ssl文件夹下,使用命令/usr/sbin/apxs -i -a -D HAVE_OPENSSL=1 -I/usr/include/openssl/ -L/usr/lib/openssl/ -c *.c -lcrypto -lssl -ldl (apxs需要安装http-devel才有,虽然如此,我还是没有编译成功,于是就在其他已经编译了这个模块的机器上拷贝mod_ssl.so到apache模块目录/usr/local/apache/modules)

  • 相关阅读:
    LeetCode 769. Max Chunks To Make Sorted
    LeetCode 845. Longest Mountain in Array
    LeetCode 1059. All Paths from Source Lead to Destination
    1129. Shortest Path with Alternating Colors
    LeetCode 785. Is Graph Bipartite?
    LeetCode 802. Find Eventual Safe States
    LeetCode 1043. Partition Array for Maximum Sum
    LeetCode 841. Keys and Rooms
    LeetCode 1061. Lexicographically Smallest Equivalent String
    LeetCode 1102. Path With Maximum Minimum Value
  • 原文地址:https://www.cnblogs.com/liaojiafa/p/6028816.html
Copyright © 2011-2022 走看看