apache笔记
2019-04-18
安装
sudo apt install php7.2 sudo apt install apache2 sudo apt install php7.2-mysql sudo apt install mysql-server mysql-client
|
常用命令
sudo service mysql start sudo service apache2 restart sudo /usr/sbin/apache2ctl start
|
配置
apache2
配置目录/etc/apache2
目录说明: xxx-available
是apache2可用的模块, xxx-enabled
是已经开启的模块, 如果模块开启了, 则xxx-enabled
下会有一个指向xxx-available
对应模块的软连接, 如果没有则说明没有开启
修改apache2
默认目录
- 修改
/etc/apache2/sites-enabled/000-default.conf
(本地服务器提供的目录)
- 修改
/etc/apache2/apache2.conf
(为本地服务器的目录提供权限)
<Directory /{你的目录,不要加/}> Require all granted <Directory>
|
- 如果没有设置浏览目录权限, 则要有默认主页文件
index.{后缀名任意}
开启浏览目录权限
<Directory /{你的目录,不要加/}> Options Indexes <Directory>
|
端口
修改apache2
默认端口
- 修改
/etc/apache2/sites-enabled/000-default.conf
- 修改
/etc/apache2/ports.conf
注意https
和http
的区别
多端口
ports.conf
增加Listen
sites-enabled/000-default.conf
增加<VirtualHost *:{端口}></VirtualHost>
启用https
仅localhost
参考: stackoverflow, 输入网址chrome://flags/#allow-insecure-localhost
进行设置, 此外还需要清除缓存之类(TODO)
自签名SSL证书
参考: https://majing.io/posts/10000050311000
- 创建认证中心, Certificate Authority(CA)
openssl genrsa -des3 -out myCA.key 2048 openssl req -x509 -new -nodes -key myCA.key -sha256 -days 825 -out myCA.pem
|
- 创建
localhost.ext
authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = localhost
|
- 创建证书
openssl genrsa -out localhost.key 2048 openssl req -new -key localhost.key -out localhost.csr openssl x509 -req -in localhost.csr -CA myCA.pem -CAkey myCA.key -CAcreateserial -out localhost.crt -days 825 -sha256 -extfile localhost.ext
|
sudo a2enmod ssl sudo systemctl restart apache2 sudo a2ensite default-ssl sudo systemctl reload apache2
|
修改/etc/apache2/sites-enabled/default-ssl.conf
:
SSLEngine on SSLCertificateFile /home/lynx/darkin_blade/m3u8/https/localhost.crt SSLCertificateKeyFile /home/lynx/darkin_blade/m3u8/https/localhost.key
|
TODO
常见错误
无法启动apache
: 找不到libphpx.x.so
以php7.4
为例
apt-file search "libphp7.4.so" libapache2-mod-php7.4: /usr/lib/apache2/modules/libphp7.4.so sudo apt install libapache2-mod-php7.4
|
403 Forbidden