在 Ubuntu 上,Apache(通常是 Apache2)可配置的内容非常多,下面按常见分类给你一个较全的清单,适合入门和运维参考。
sudo apt install apache2
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
主要目录:
/etc/apache2//var/www/html/var/log/apache2/文件:/etc/apache2/apache2.conf
可配置:
ServerNameTimeoutKeepAliveMaxClients / MaxRequestWorkersDirectoryIndex<Directory>)文件:/etc/apache2/ports.conf
Listen 80
Listen 443
目录:
/etc/apache2/sites-available//etc/apache2/sites-enabled/示例:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
可配:
启用:
sudo a2ensite example.conf
sudo systemctl reload apache2
查看已启用:
apache2ctl -M
常用模块:
rewrite:URL 重写ssl:HTTPSproxy / proxy_http:反向代理headers:HTTP 头deflate:压缩cache:缓存启用/禁用:
sudo a2enmod rewrite
sudo a2dismod status
使用 Let’s Encrypt:
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
可配:
RewriteEngine On
RewriteRule ^old.html$ new.html [R=301,L]
常用于:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
常用于:
ServerTokens Prod
ServerSignature Off
apache2ctl configtest
apache2ctl -S
sudo a2enmod / a2dismod
sudo a2ensite / a2dissite
如果你愿意,可以告诉我:
我可以直接给你一份可复制的配置文件示例。