Linux系统下Apache+OpenSSL源码安装并配置https服务

来源:互联网 发布:linux画面撕裂 编辑:程序博客网 时间:2024/05/16 11:21

软件版本:

Apache 2.4.23
OpenSSL-1.0.2h

一 支持软件安装

1. 安装apr

./configure --prefix=/path/apr (path为安装apr的路径)

sudo make

sudo make install

2. 安装apr-util

./configure --prefix=/path/apr-util --with-apr=/path/apr

sudo make

sudo make install

3. 安装pcre

./configure --prefix=/path/pcre

sudo make

sudo make install

(注:不要安装pcre2,否则会出现error: Did not find pcre-config script at /path/pcre)


二 安装httpd

sudo ./configure --prefix=path --enable-so --enable-ssl --with-ssl=/usr/local/ssl --enable-mods-shared=all --enable-static-ab --with-apr=/path/apr --with-apr-util=/path/apr-util --with-pcre=/path/pcre (path为httpd的安装路径) (/usr/local/ssl为OpenSSL的安装路径)

sudo make

sudo make install


三 生成证书

1. 生成一个RSA密钥

openssl genrsa -out server.key

2. 生成一个证书请求

openssl req -new -key server.key -out server.csr

3. 自己签发证书

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt


四 配置httpd.conf文件

1. Listen 80

2. LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

    (注:若不加载该模块,httpd-ssl.conf会报SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).)

3. LoadModule ssl_module modules/mod_ssl.so

4. ServerName IP/WebSite:80

5. Include conf/extra/proxy-html.conf


五 配置httpd-ssl.conf文件

1. Listen 443

2. DocumentRoot 可以改为自己存放页面的路径,例如/usr/local/pages

    改变路径后,需要添加以下指令使得用户具有访问该路径中页面的权限

    <Directory “/usr/local/pages”>

Options Indexes FollowSymLinks

        Override None

        Require all granted

    </Directory>

3. ServerName IP/WebSite:443

4. SSLCertificateFile "/path/server.crt" (path为放置server.crt的路径)

5. SSLCertificateKeyFile "/path/server.key" (path为放置server.key的路径)


六 注意

1. DocumentRoot 对应的文件路径中的所有parent directories都应该具有可执行权限即x-bit应该被设置为1,否则客户端在访问页面时会出现Forbidden:You don't have permission to access /on this server. 这样的问题。

0 0
原创粉丝点击