# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.
# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
# /etc/apache2/
# |-- apache2.conf
# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf-enabled
# | `-- *.conf
# `-- sites-enabled
# `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
# together by including all remaining configuration files when starting up the
# web server.
#
# * ports.conf is always included from the main configuration file. It is
# supposed to determine listening ports for incoming connections which can be
# customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
# directories contain particular configuration snippets which manage modules,
# global configuration fragments, or virtual host configurations,
# respectively.
#
# They are activated by symlinking available configuration files from their
# respective *-available/ counterparts. These should be managed by using our
# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
# their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
# the default configuration, apache2 needs to be started/stopped with
# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
# work with the default configuration.
# Global configuration
#
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE! If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/etc/apache2"
#ServerName exemplo.com.br
#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#Mutex file:${APACHE_LOCK_DIR} default
#
# The directory where shm and other runtime files will be stored.
#
DefaultRuntimeDir ${APACHE_RUN_DIR}
#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 180
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 600
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 9
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log
#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn
# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
# Include list of ports to listen on
Include ports.conf
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory "/">
Options None
AllowOverride None
Require all denied
</Directory>
<Directory "/usr/share">
AllowOverride None
Require all denied
</Directory>
<Directory "/var/www/">
Options None
AllowOverride None
DirectoryIndex index.py index.php indez.pl index
Require all denied
<FilesMatch ".+\.(phtml|htm|html|asp|py|pl)$">
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"
</FilesMatch>
<LimitExcept GET POST HEAD>
Require all denied
</LimitExcept>
</Directory>
#
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
<Directory "/var/www/exemplo">
Options +SymLinksIfOwnerMatch +ExecCGI -Indexes -MultiViews
AllowOverride None
DirectoryIndex index.py index.php indez.pl index
Require all granted
<Files "*.php">
#Allow from all
Require valid-user
Allow from 127.0.0.1
#Allow from 12.123.123.123
Satisfy Any
</Files>
<Files "index.py">
Require all granted
</Files>
<LimitExcept GET POST HEAD>
Require all denied
</LimitExcept>
#IndexIgnore *.php *.js *.css *.html *.log *.sql *.pdf *.swf *.rtf *.doc *.odt *.asp *.py
#RewriteRule ^arquivo\.php$ arquivos/arquivo.php
RewriteEngine on
#ReWriteRule ^About_us$ About_us.html [NC]
RewriteBase "/"
#RewriteRule "\.js" "-" [F]
#RewriteRule "\.css" "-" [F]
# Evitar que outros utilizem as imagens consumindo banda
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?exemplo.com.br [NC]
RewriteRule \.(jpg|jpeg|png|gif|webp|ico)$ - [NC,F,L]
#
# Remover extensão dos arquivos (exemplo: /arquivo.php para /arquivo)
# A extensões devem ser removidas no html também, por exemplo,
# 'arquivo.php' ou 'arquivo.asp', etc, deve ficar somente 'arquivo', senão bloqueia o POST.
RewriteCond %{THE_REQUEST} ^[A-Z]{2,}\s([^.]+)\.py [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.py -f
RewriteRule ^(.*?)/?$ $1.py [L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.asp [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^(.*?)/?$ $1.asp [L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
# Esta regra logo abaixo leva para o example.com da IANA
#RewriteRule ^(.*)$ www.exemplo.com.br/$1 [NC]
# Ocultam pasta do caminho da URL, os caminhos no html devem ser alterados também
RewriteRule "^index_pasta(.*)$" "pasta/pasta.py" [L]
RewriteRule "^tabelaspasta(.*)$" "pasta/tabelaspasta.py" [L]
RewriteRule "^loginpasta(.*)$" "pasta/loginpasta.asp" [L]
RewriteRule "^index_logado_prof(.*)$" "pasta/index_logado_prof.asp" [L]
RewriteRule "^cad_usu_pasta(.*)$" "pasta/cad_usu_pasta.asp" [L]
#
# Bloqueio de bots
RewriteCond %{HTTP_USER_AGENT} MJ12bot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} AhrefsBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} SEMrushBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Bytespider [NC,OR]
RewriteCond %{HTTP_USER_AGENT} DotBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} MauiBot [NC]
RewriteCond %{HTTP_USER_AGENT} (gumgum-bot|postmanruntime|ag_dm_spider|scrapy|chimebot) [NC]
RewriteRule .* - [F,L]
</Directory>
<Directory "/var/www/html">
Options None
AllowOverride None
DirectoryIndex None
Require all denied
<LimitExcept GET POST HEAD>
Require all denied
</LimitExcept>
</Directory>
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
# AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
Satisfy All
</FilesMatch>
#
<Files "index.php">
Require all granted
# Order Allow,Deny
# Allow from all
</Files>
#
<FilesMatch "^\.">
Require all denied
Satisfy All
</FilesMatch>
#
<DirectoryMatch "^(.*/)*\..*">
Require all denied
Satisfy All
</DirectoryMatch>
#
<LocationMatch "^(.*/)\..*">
Require all denied
Satisfy All
</LocationMatch>
#
# Apache2 Tunning
#<IfModule mpm_prefork_module>
# # Número de processos de servidor filho criados na inicialização:
# StartServers 4
# # Número mínimo de processos de servidor filho ociosos:
# MinSpareServers 20
# # Número máximo de processos de servidor filho ociosos:
# MaxSpareServers 40
# # Número máximo de conexões que serão processadas simultaneamente:
# MaxRequestWorkers 200
# # Limita o número de conexões que um servidor filho individual manipulará durante sua vida útil:
# MaxConnectionsPerChild 4500
#</IfModule>
#
<IfModule mpm_event_module>
# Define o limite superior do número de processos (padrão 16):
ServerLimit 10
# Número de processos de servidores filhos criados na inicialização (padrão 3):
StartServers 3
# Número mínimo de processos de servidor filho ociosos:
## MinSpareServers 20
# Número máximo de conexões que serão processadas simultaneamente (padrão 256):
MaxRequestWorkers 250
# Número mínimo de threads ociosas em todo o servidor (padrão 75):
MinSpareThreads 75
# Número máximo de processos de servidor filho ociosos:
## MaxSpareServers 40
# Número máximo de threads ociosas em todo o servidor (padrão 250):
MaxSpareThreads 200
# Define o número de threads criadas por processo filho (padrão 25):
ThreadsPerChild 25
# Define o valor máximo para ThreadsPerChild (padrão 64):
ThreadLimit 64
# Limita o número de conexões que um processo individual de servidor filho manipulará durante sua vida útil:
MaxConnectionsPerChild 4480
# Define o limite de conexões simultâneas por processo (padrão 2):
AsyncRequestWorkerFactor 2
</IfModule>
#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#
AddType fcgid(73|74|80|81|82|83)-script .php .phtml .htm .html .asp .py .pl
AddType application/x-httpd-php .php .phtml .htm .html .asp .py .pl
AddType application/x-httpd-php-source .php .php8
AddType application/wasm .wasm
#
#AddHandler fcgid(73|74|80|81|82|83)-script .php .phtml .htm .html .asp .py .pl
AddHandler application/x-httpd-php .php .phtml .htm .html .asp .py .pl
#AddHandler application/x-httpd-php-source .php .php3 .php4 .php5 .php6 .php7 .php8
#AddHandler application/wasm .wasm
#
AddHandler fcgid(73|74|80|81|82|83)-script .fcgi .php .phtml .htm .html .asp .py .pl
#FcgidConnectTimeout 20
#FcgidMaxRequestLen 10485760
#FcgidMaxProcessesPerClass 10
#FcgidIOTimeout 100
#
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
#
ErrorDocument 400 "Requisição mal feita pelo cliente!"
#ErrorDocument 400 /cgi-bin/crash-recover
ErrorDocument 400 https://www.exemplo.com.br/errors.html
#
# Na diretiva 401 não pode usar URI absoluta.
#ErrorDocument 401 /errors.html
ErrorDocument 401 "Necessita Autorização!"
#ErrorDocument 401 /cgi-bin/crash-recover
ErrorDocument 401 /bazinga
#ErrorDocument 401 /subscription_info.html
#
ErrorDocument 403 "Acesso não permitido, estamos de olho!"
#ErrorDocument 403 Forbidden!
#ErrorDocument 403 /cgi-bin/crash-recover
#ErrorDocument 403 /errors/forbidden.py?referrer=%{escape:%{HTTP_REFERER}}
ErrorDocument 403 https://www.exemplo.com.br/bazinga
#
#ErrorDocument 404 /errors/bad_urls.php
ErrorDocument 404 "Página não encontrada!"
##ErrorDocument 404 /cgi-bin/crash-recover
ErrorDocument 404 https://www.exemplo.com.br/bazinga
#
ErrorDocument 408 "Excedeu o tempo da requisição!"
#ErrorDocument 408 /cgi-bin/crash-recover
ErrorDocument 408 https://www.exemplo.com.br/errors.html
#
ErrorDocument 500 "Deu um problema no Servidor!"
#ErrorDocument 500 /cgi-bin/crash-recover
ErrorDocument 500 https://www.exemplo.com.br/errors.html
#ErrorDocument 500 ttps://example.com/cgi-bin/server-error.cgi
#
ErrorDocument 501 "O Servidor não suporta essa função!"
#ErrorDocument 501 /cgi-bin/crash-recover
ErrorDocument 501 https://www.exemplo.com.br/errors.html
#
# 1xx – Solicitações informativas
# 2xx – Solicitações bem-sucedidas
# 3xx – Redirecionamentos
# 4xx – Erros do lado do cliente
# 5xx – Erros do lado do servidor
#
# 400 Bad request
# 401 Authorization required
# 403 Forbidden
# 404 Not Found
# 405 Method not implemented
# 407 Proxy authentication required
# 408 Request time-out
# 500 Internal server error
# 501 Not implemented
# 502 Bad gateway
# 503 Service unavailable (many requests)
# 504 Gateway time-out
# 505 HTTP version not supported
#
# 200 URL encontrada e transmissão concluída com sucesso.
# 400 Solicitação (request) incompreensível, protocolo inexistente ou tipo incompatível.
# 404 Não foi encontrada a URL solicitada.
# 405 O servidor não suporta o método solicitado.
# 500 Erro desconhecido de natureza do servidor.
# 503 Capacidade máxima do servidor alcançada.
# De 200 até 299: Requisições bem sucedidas
# De 300 até 399: Informações
# 301 - Move Permanently
# 302 - Move Temporarily
# 305 - Use Proxy
# De 400 até 499: Erros de solicitação (request)
# De 500 até 599: Erros do servidor e/ou programação
#
ServerTokens ProductOnly
ServerSignature Off
TraceEnable Off
#
<IfModule mod_headers.c>
# Add security and privacy related headers
# Header always set Access-Control-Allow-Origin "https://www.exemplo.com.br/"
Header set Content-Security-Policy "upgrade-insecure-requests;"
Header always set Permissions-Policy "accelerometer=(),autoplay=(),camera=(),encrypted-media=(),fullscreen=*,gyroscope=(),interest-cohort=(),magnetometer=(),microphone=(),midi=(),sync-xhr=*,usb=(),xr-spatial-tracking=(),geolocation=*"
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always edit Set-Cookie (.*) "$1; HttpOnly; Secure"
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy "strict-origin, strict-origin-when-cross-origin"
Header always set X-Frame-Options "SAMEORIGIN"
SetEnv modHeadersAvailable true
</IfModule>
#
<IfModule security2_module>
Include /etc/modsecurity/crs/*.conf
Include /etc/modsecurity/modsecurity.conf
</IfModule>
#
# Mod Status
# Você pode acessar as estatísticas do servidor usando um navegador da Web para acessar a página http://your.server.name/server-status:
#<Location "/server-status">
# SetHandler server-status
# Require host www.exemplo.com.br
# Require all granted
#</Location>
#
AddDefaultCharset UTF-8
#LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
#LoadModule proxy_fcgi_module /usr/lib/apache2/modules/mod_proxy_fcgi.so
# Habilite os módulos:
# a2enmod expires
# a2enmod rewrite
# a2enmod status
# a2enmod mpm_prefork # para php-fpm precisa desabilitar
# a2enmod headers
# a2enmod ssl
# a2dismod php8.3 # disable modphp (opcional)
# a2dismod mpm_prefork # para php-fpm, precisa trocar para mpm_event
# a2enmod mpm_event # enable mpm_event
# a2enmod proxy_fcgi setenvif # enable proxy_fcgi, precisa para php-fpm
# a2enconf php8.3-fpm # enable php8.3-fpm
# a2enmod proxy
# a2enmod status
# apt-get install libapache2-mod-evasive
# apt-get install libapache2-mod-security2
# IPv6 2a02:4780:14:2d67::1
# ttps://securityheaders.com/
#
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
#
# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.
# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
#