Thời gian đọc: 18 phút
apache2.conf
)Tệp cấu hình chính của Apache2, chứa các thiết lập toàn cục cho máy chủ web.
/etc/apache2/apache2.conf
ServerRoot
, Listen
, User
, Group
, và Include
để tải các tệp cấu hình khác.ServerRoot "/etc/apache2"
Listen 80
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Include /etc/apache2/sites-enabled/
ports.conf
)Tệp cấu hình để chỉ định các cổng mà Apache lắng nghe.
/etc/apache2/ports.conf
Listen
: Xác định các cổng mà Apache sẽ lắng nghe.Listen 80
Listen 443
000-default.conf
)Tệp cấu hình cho trang web mặc định không sử dụng SSL.
/etc/apache2/sites-available/000-default.conf
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
default-ssl.conf
)Tệp cấu hình cho trang web SSL mặc định.
/etc/apache2/sites-available/default-ssl.conf
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
mods-available/
và mods-enabled/
)/etc/apache2/mods-available/
và /etc/apache2/mods-enabled/
mods-available/
chứa các mô-đun có sẵn.mods-enabled/
chứa các mô-đun đang được kích hoạt, được tạo bằng cách tạo liên kết đến các tệp trong mods-available/
.sites-available/
và sites-enabled/
)/etc/apache2/sites-available/
và /etc/apache2/sites-enabled/
sites-available/
chứa các tệp cấu hình cho các trang web có sẵn.sites-enabled/
chứa các trang web đang được kích hoạt, được tạo bằng cách tạo liên kết đến các tệp trong sites-available/
..htaccess
Tệp cấu hình cho các thiết lập cấp thư mục.
/var/www/html/.htaccess
RewriteEngine
, AuthType
, và AllowOverride
.RewriteEngine On
RewriteRule ^oldpage.html$ newpage.html [R=301,L]
security.conf
Cấu hình liên quan đến bảo mật.
/etc/apache2/conf-available/security.conf
ServerTokens
, ServerSignature
, và TraceEnable
.ServerTokens Prod
ServerSignature Off
TraceEnable Off
charset.conf
Cấu hình mã hóa ký tự.
/etc/apache2/conf-available/charset.conf
AddDefaultCharset UTF-8
userdir.conf
Cấu hình cho các thư mục người dùng.
/etc/apache2/mods-available/userdir.conf
UserDir public_html
AllowOverride FileInfo AuthConfig Limit
Require all granted
autoindex.conf
Cấu hình tự động tạo danh sách thư mục.
/etc/apache2/mods-available/autoindex.conf
index
tệp.
IndexOptions FancyIndexing
IndexOrderDefault Descending Date
deflate.conf
Cấu hình nén Gzip.
/etc/apache2/mods-available/deflate.conf
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
headers.conf
Cấu hình tiêu đề HTTP.
/etc/apache2/mods-available/headers.conf
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
Header set X-Frame-Options "SAMEORIGIN"
Header unset Server
expires.conf
Cấu hình thời gian hết hạn của tệp.
/etc/apache2/mods-available/expires.conf
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
rewrite.conf
Cấu hình mô-đun mod_rewrite cho các quy tắc chuyển hướng URL.
/etc/apache2/mods-available/rewrite.conf
RewriteEngine On
RewriteRule ^oldpage.html$ newpage.html [R=301,L]
ssl.conf
Cấu hình cho SSL/TLS.
/etc/apache2/mods-available/ssl.conf
SSLEngine
, SSLCertificateFile
, và SSLCertificateKeyFile
.
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!aNULL:!MD5
SSLHonorCipherOrder on
SSLEngine on
logrotate.conf
Cấu hình quay vòng nhật ký.
/etc/logrotate.d/apache2
/var/log/apache2/*.log {
weekly
missingok
rotate 12
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
if [ -f /var/run/apache2/apache2.pid ]; then
/etc/init.d/apache2 reload > /dev/null
fi
endscript
}
security2.conf
Cấu hình bảo mật nâng cao.
/etc/apache2/conf-available/security2.conf
ServerTokens Prod
ServerSignature Off
TraceEnable Off
apache2ctl
Công cụ điều khiển Apache2 từ dòng lệnh.
/usr/sbin/apache2ctl
apache2ctl start
apache2ctl stop
apache2ctl restart
apache2ctl configtest
access.conf
Cấu hình quyền truy cập cho các thư mục.
/etc/apache2/conf-available/access.conf
Require
, Allow
, và Deny
.
AllowOverride none
Require all denied
AllowOverride None
Require all granted
mod_status.conf
Cấu hình để sử dụng mô-đun mod_status
theo dõi trạng thái máy chủ.
/etc/apache2/mods-available/status.conf
ExtendedStatus On
SetHandler server-status
Require host example.com
mod_userdir.conf
Cấu hình cho các thư mục cá nhân.
/etc/apache2/mods-available/userdir.conf
public_html
.
UserDir public_html
AllowOverride FileInfo AuthConfig Limit
Require all granted
mod_negotiation.conf
Cấu hình cho đàm phán nội dung.
/etc/apache2/mods-available/negotiation.conf
Options Indexes Includes FollowSymLinks
mod_alias.conf
Cấu hình cho các alias và redirects.
/etc/apache2/mods-available/alias.conf
Alias /icons/ "/usr/share/apache2/icons/"
Options Indexes MultiViews
AllowOverride None
Require all granted
mod_cgi.conf
Cấu hình cho mô-đun CGI.
/etc/apache2/mods-available/cgi.conf
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI
Require all granted
mod_dav.conf
Cấu hình cho mô-đun DAV.
/etc/apache2/mods-available/dav.conf
DavLockDB /var/lib/dav/lockdb
mod_dav_fs.conf
Cấu hình cho mô-đun DAV filesystem.
/etc/apache2/mods-available/dav_fs.conf
DavMinTimeout 600
mod_proxy.conf
Cấu hình cho mô-đun proxy.
/etc/apache2/mods-available/proxy.conf
ProxyRequests Off
Order deny,allow
Deny from all
Allow from localhost
mod_proxy_http.conf
Cấu hình cho proxy HTTP.
/etc/apache2/mods-available/proxy_http.conf
ProxyPass /example http://example.com/
ProxyPassReverse /example http://example.com/
mod_proxy_balancer.conf
Cấu hình cho cân bằng tải proxy.
/etc/apache2/mods-available/proxy_balancer.conf
BalancerMember http://192.168.1.1
BalancerMember http://192.168.1.2
ProxyPass / balancer://mycluster/
mod_ssl.conf
Cấu hình cho mô-đun SSL.
/etc/apache2/mods-available/ssl.conf
SSLEngine
, SSLCertificateFile
, và SSLCertificateKeyFile
.
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!aNULL:!MD5
SSLHonorCipherOrder on
SSLEngine on
mod_rewrite.conf
Cấu hình cho mô-đun mod_rewrite.
/etc/apache2/mods-available/rewrite.conf
RewriteEngine On
RewriteRule ^oldpage.html$ newpage.html [R=301,L]
mod_access_compat.conf
Cấu hình cho mô-đun tương thích quyền truy cập.
/etc/apache2/mods-available/access_compat.conf
# Các cấu hình cụ thể nếu cần thiết
mod_brotli.conf
Cấu hình cho mô-đun Brotli nén.
/etc/apache2/mods-available/brotli.conf
BrotliCompressionQuality 5
BrotliWindowSize 16
AddOutputFilterByType BROTLI_COMPRESS text/html
AddOutputFilterByType BROTLI_COMPRESS text/css
AddOutputFilterByType BROTLI_COMPRESS text/javascript
mod_gnutls.conf
Cấu hình cho mô-đun GnuTLS.
/etc/apache2/mods-available/gnutls.conf
GNUTLSProtocol TLSv1.2
GNUTLSCipherSuite NORMAL
GNUTLSCertificateFile /etc/ssl/certs/ssl-cert.pem
GNUTLSCertificateKeyFile /etc/ssl/private/ssl-cert.key
mod_status.conf
Cấu hình trạng thái của máy chủ.
/etc/apache2/mods-available/status.conf
ExtendedStatus On
SetHandler server-status
Require host localhost
mod_authz_core.conf
Cấu hình cho mô-đun mod_authz_core
.
/etc/apache2/mods-available/authz_core.conf
Require all granted
mod_authz_host.conf
Cấu hình cho mô-đun mod_authz_host
.
/etc/apache2/mods-available/authz_host.conf
Order allow,deny
Allow from all
mod_authz_user.conf
Cấu hình cho mô-đun mod_authz_user
.
/etc/apache2/mods-available/authz_user.conf
Require valid-user
mod_auth_basic.conf
Cấu hình cho mô-đun mod_auth_basic
.
/etc/apache2/mods-available/auth_basic.conf
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
mod_auth_digest.conf
Cấu hình cho mô-đun mod_auth_digest
.
/etc/apache2/mods-available/auth_digest.conf
AuthType Digest
AuthName "Digest Authentication"
AuthDigestProvider file
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
mod_auth_form.conf
Cấu hình cho mô-đun mod_auth_form
.
/etc/apache2/mods-available/auth_form.conf
AuthFormProvider file
AuthName "Form Authentication"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
mod_authnz_ldap.conf
Cấu hình cho mô-đun mod_authnz_ldap
.
/etc/apache2/mods-available/authnz_ldap.conf
AuthType Basic
AuthName "LDAP Authentication"
AuthLDAPURL ldap://localhost:389/ou=users,dc=example,dc=com
AuthLDAPBindDN "cn=admin,dc=example,dc=com"
AuthLDAPBindPassword "password"
Require valid-user
mod_authz_owner.conf
Cấu hình cho mô-đun mod_authz_owner
.
/etc/apache2/mods-available/authz_owner.conf
Require owner
mod_autoindex.conf
Cấu hình cho mô-đun mod_autoindex
.
/etc/apache2/mods-available/autoindex.conf
IndexOptions FancyIndexing
IndexOrderDefault Descending Date
mod_cgi.conf
Cấu hình cho mô-đun mod_cgi
.
/etc/apache2/mods-available/cgi.conf
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI
Require all granted
mod_dav.conf
Cấu hình cho mô-đun mod_dav
.
/etc/apache2/mods-available/dav.conf
DavLockDB /var/lib/dav/lockdb
mod_dav_fs.conf
Cấu hình cho mô-đun mod_dav_fs
.
/etc/apache2/mods-available/dav_fs.conf
DavMinTimeout 600
mod_proxy.conf
Cấu hình cho mô-đun mod_proxy
.
/etc/apache2/mods-available/proxy.conf
ProxyRequests Off
Order deny,allow
Deny from all
Allow from localhost
mod_proxy_http.conf
Cấu hình cho mô-đun mod_proxy_http
.
/etc/apache2/mods-available/proxy_http.conf
ProxyPass /example http://example.com/
ProxyPassReverse /example http://example.com/
mod_proxy_balancer.conf
Cấu hình cho mô-đun mod_proxy_balancer
.
/etc/apache2/mods-available/proxy_balancer.conf
BalancerMember http://192.168.1.1
BalancerMember http://192.168.1.2
ProxyPass / balancer://mycluster/
mod_proxy_ftp.conf
Cấu hình cho mô-đun mod_proxy_ftp
.
/etc/apache2/mods-available/proxy_ftp.conf
# Cấu hình cụ thể nếu cần
mod_proxy_uwsgi.conf
Cấu hình cho mô-đun mod_proxy_uwsgi
.
/etc/apache2/mods-available/proxy_uwsgi.conf
# Cấu hình cụ thể nếu cần
mod_auth_openidc.conf
Cấu hình cho mô-đun mod_auth_openidc
.
/etc/apache2/mods-available/auth_openidc.conf
OIDCProviderMetadataURL https://example.com/.well-known/openid-configuration
OIDCClientID my-client-id
OIDCClientSecret my-client-secret
mod_headers.conf
Cấu hình cho mô-đun mod_headers
.
/etc/apache2/mods-available/headers.conf
Header set X-Content-Type-Options nosniff
Header set X-XSS-Protection "1; mode=block"
Header set X-Frame-Options DENY
mod_expires.conf
Cấu hình cho mô-đun mod_expires
.
/etc/apache2/mods-available/expires.conf
ExpiresActive On
ExpiresDefault "access plus 1 month"
mod_deflate.conf
Cấu hình cho mô-đun mod_deflate
.
/etc/apache2/mods-available/deflate.conf
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
mod_mime.conf
Cấu hình cho mô-đun mod_mime
.
/etc/apache2/mods-available/mime.conf
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType image/svg+xml .svg .svgz
mod_mime_magic.conf
Cấu hình cho mô-đun mod_mime_magic
.
/etc/apache2/mods-available/mime_magic.conf
MIMEMagicFile /etc/apache2/magic
mod_mpm_prefork.conf
Cấu hình cho mô-đun MPM Prefork.
/etc/apache2/mods-available/mpm_prefork.conf
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0
mod_mpm_event.conf
Cấu hình cho mô-đun MPM Event.
/etc/apache2/mods-available/mpm_event.conf
StartServers 5
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 0
mod_mpm_worker.conf
Cấu hình cho mô-đun MPM Worker.
/etc/apache2/mods-available/mpm_worker.conf
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 0
mod_authnz_ldap.conf
Cấu hình cho mô-đun mod_authnz_ldap
.
/etc/apache2/mods-available/authnz_ldap.conf
AuthType Basic
AuthName "LDAP Authentication"
AuthLDAPURL ldap://localhost:389/ou=users,dc=example,dc=com
AuthLDAPBindDN "cn=admin,dc=example,dc=com"
AuthLDAPBindPassword "password"
Require valid-user
mod_remoteip.conf
Cấu hình cho mô-đun mod_remoteip
.
/etc/apache2/mods-available/remoteip.conf
RemoteIPHeader X-Forwarded-For
mod_suexec.conf
Cấu hình cho mô-đun mod_suexec
.
/etc/apache2/mods-available/suexec.conf
suexec
cho phép chạy các tệp CGI dưới quyền của người dùng khác.
SuexecUserGroup "#1001" "#1001"
mod_auth_form.conf
Cấu hình cho mô-đun mod_auth_form
.
/etc/apache2/mods-available/auth_form.conf
AuthFormProvider file
AuthName "Form Authentication"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
mod_authnz_pam.conf
Cấu hình cho mô-đun mod_authnz_pam
.
/etc/apache2/mods-available/authnz_pam.conf
AuthPAM_Enabled On
mod_php.conf
Cấu hình cho mô-đun PHP.
/etc/apache2/mods-available/php.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
mod_rewrite.conf
Cấu hình cho mô-đun mod_rewrite
.
/etc/apache2/mods-available/rewrite.conf
RewriteEngine On
RewriteRule ^oldpage.html$ newpage.html [R=301,L]
mod_ssl.conf
Cấu hình cho mô-đun SSL.
/etc/apache2/mods-available/ssl.conf
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!aNULL:!MD5
SSLHonorCipherOrder on
SSLCertificateFile /etc/ssl/certs/ssl-cert.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert.key
mod_userdir.conf
Cấu hình cho mô-đun mod_userdir
.
/etc/apache2/mods-available/userdir.conf
UserDir public_html
AllowOverride FileInfo AuthConfig Limit Indexes
Options Indexes Includes FollowSymLinks
Require all granted
mod_authnz_fcgi.conf
Cấu hình cho mô-đun mod_authnz_fcgi
.
/etc/apache2/mods-available/authnz_fcgi.conf
# Cấu hình cụ thể nếu cần
mod_dbd.conf
Cấu hình cho mô-đun mod_dbd
.
/etc/apache2/mods-available/dbd.conf
DBDMin 4
DBDMax 10
DBDKeep
mod_authz_groupfile.conf
Cấu hình cho mô-đun mod_authz_groupfile
.
/etc/apache2/mods-available/authz_groupfile.conf
AuthGroupFile /etc/apache2/groups
mod_ldap.conf
Cấu hình cho mô-đun mod_ldap
.
/etc/apache2/mods-available/ldap.conf
LDAPSharedCacheSize 100
LDAPCacheEntries 1000
LDAPCacheTTL 600
mod_cache.conf
Cấu hình cho mô-đun mod_cache
.
/etc/apache2/mods-available/cache.conf
CacheRoot /var/cache/apache2/mod_cache
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
mod_sasl.conf
Cấu hình cho mô-đun mod_sasl
.
/etc/apache2/mods-available/sasl.conf
# Cấu hình cụ thể nếu cần
mod_ssl.conf
Cấu hình cho mô-đun SSL.
/etc/apache2/mods-available/ssl.conf
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!aNULL:!MD5
SSLHonorCipherOrder on
SSLCertificateFile /etc/ssl/certs/ssl-cert.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert.key
mod_xml2enc.conf
Cấu hình cho mô-đun mod_xml2enc
.
/etc/apache2/mods-available/xml2enc.conf
AddDefaultCharset UTF-8
mod_phpmyadmin.conf
Cấu hình cho mô-đun mod_phpmyadmin
.
/etc/apache2/mods-available/phpmyadmin.conf
Alias /phpmyadmin /usr/share/phpmyadmin
Options Indexes FollowSymLinks
AllowOverride Limit
Require all granted