ubuntu 20.04 部署 apache2 http和https 您所在的位置:网站首页 服务设置了自动启动但是没有启动 ubuntu 20.04 部署 apache2 http和https

ubuntu 20.04 部署 apache2 http和https

#ubuntu 20.04 部署 apache2 http和https| 来源: 网络整理| 查看: 265

安装 Apache2 sudo apt update sudo apt install apache2

安装之后,apache2服务器已经启动,并且会随系统自动启动;

Apache2 配置

Apache配置文件在/etc/apache2目录下。

主配置文件是apache2.conf,其中引用了其他配置文件。

a2query命令可以获取服务器当前的运行配置。

环境变量

envvars文件中配置了Apache用到的环境变量,这些环境变量也可以在配置文件中引用。

模块配置

所有模块配置在mods-available目录下,启用后会在mods-enabled目录下建立符号链接; 启用模块用a2enmod命令,禁用模块用a2dismod命令。

监听端口配置

ports.conf 文件中配置了Apache服务器监听的端口,包括HTTP端口和HTTPS端口 默认包括HTTP端口80,如果加载了SSL或TLS模块,还会监听443端口。 除了这里的配置,各虚拟主机配置里也会配置其对应的端口。

其他可选配置

其他可选配置在conf-available目录下,启用的配置会链接到conf-enabled中。 启用配置用a2enconf命令,禁用配置用a2disconf命令。

网站(虚拟主机)配置

网站配置包含了HTTP配置和HTTPS配置,根据需要选择。 所有网站配置都放在sites-available子目录中,而启用的网站则会链接到sites-enabled目录下。 要启动网站可以用a2ensite命令,禁用网站则用a2dissite命令。

网站配置 HTTP网站配置

默认配置中已经启用了一个http网站000-default, 其中配置了网站主目录DocumentRoot /var/www/html等信息,可参考 000-default.conf 在 sites-available 目录下配置其他网站,配置后通过 a2ensite 命令启动。

配置后可以通过 http://127.0.0.1 访问 注意使用的地址要与配置文件中的ServerName匹配

HTTPS网站

启用HTTPS必须要加载ssl模块

a2enmod ssl systemctl restart apache2

启动SSL网站

a2ensite default-ssl systemctl reload apache2

这里使用的是默认的SSL网站配置default-ssl,与HTTP的区别在于启用了SSL引擎SSLEngine on,并且配置了SSL需要的证书和密钥,以及其他SSL运行需要的参数。

默认的SSL配置中使用的是自签名的SSL证书,在使用浏览器打开网站时会收到安全警告,在真正使用时需要申请自己的密钥和证书。

生成自签名证书:

If you install the ssl-cert package, a self-signed certificate will be automatically created using the hostname currently configured on your computer. You can recreate that certificate (e.g. after you have changed '/etc/hosts' or DNS to give the correct hostname) as user root with: make-ssl-cert generate-default-snakeoil --force-overwrite To create more certificates with different host names, you can use make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /path/to/cert-file.crt This will ask you for the hostname and place both SSL key and certificate in the file '/path/to/cert-file.crt'. Use this file with the SSLCertificateFile directive in the Apache config (you don't need the SSLCertificateKeyFile in this case as it also contains the key). The file '/path/to/cert-file.crt' should only be readable by root. A good directory to use for the additional certificates/keys is '/etc/ssl/private'.


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有