https阿里云证书购买与apache环境配置

时间:2023-03-09 15:03:29
https阿里云证书购买与apache环境配置

1.在阿里云云盾安全->CA证书购买

2.下载证书解压文件,一般有四个文件

https阿里云证书购买与apache环境配置

3.在/etc/apache2  下创建一个文件夹cert 放入以上四个文件(路径可自己任意选择)

4.$sudo a2enmod ssl

这条命令相当于
sudo ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled

如果没有a2enmod指令,也可直接在apache2.conf中设置SSL模块加载:

LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

5.在、/etc/apache2/sites-availables/default-ssl.conf中更改以下三个文件的路径为刚才上传的路径

此文件可能在/etc/apache2/sites-enabled/default-ssl.conf(保证两个地方都有此文件且内容相同即可)

SSLCertificateFile /etc/apache2/cert/public.pem
SSLCertificateKeyFile /etc/apache2/cert/214498210030298.key
SSLCertificateChainFile /etc/apache2/cert/chain.pem

6.重启apache2(/etc/init.d/apache2 restart)

7.将生成证书的域名解析到你主机的IP即可使用https访问

8.将https定位到入口指定文件

9.添加监听端口

编辑Apache端口配置(/etc/apache2/ports.conf),加入443端口(SSL缺省使用):

Listen 80

Listen 443

10.开启路由重写

Ubuntu下apache2的rewrite模块默认是不加载的。
只要运行了一下这个命令:a2enmod rewrite 就可以启用rewrite模块了。

备注:
Apaceh2 多了一组 a2enmod, a2dismod指令,用于启用和禁用Apache的模块。a2enmod用于在Apache启用指定的模块,它实际上做的是在/etc/apache2 /mods-enabled目录下创建模块文件的符号链接。相反a2dismo则是通过删除符号链接而达到禁用指定模块的功能。当然,启用已启用的模块或禁用已禁用的模块是不会报错的。^^
这里有必要说明一下:
/etc/apache2/mods-available 放apache可用的模块文件
/etc/apache2/mods-enabled 放apache已启用的模块文件的链接
弄明白了,去查看一下/etc/apache2/mods-enabled目录,果然有新增了一条rewrite.load的链接。

修改/etc/apahce2/apahce2.conf
把 下面注释部分改掉
#<Directory /var/www/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

重启apache 即可去掉index.php访问

11.配置虚拟主机

修改文件
vi /etc/apache2/sites-avilabe/000-default.conf
代码如下:
添加一条(注意端口为443)

<VirtualHost *:443>

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/laravel/public(指定文件目录)
ServerName www.xxx.com(你的域名)

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

重启apache2即可用https访问并定位到指定的文件