Syntaxes تنظیمات امنیتی در سرور Apache


# برای جلوگیری از مستقیم دسترسی به فایل‌های .htaccess
<Files .htaccess>
    Order allow,deny
    Deny from all
</Files>

# جلوگیری از نمایش لیست دایرکتوری
Options -Indexes

# فعال‌سازی تفکیک کاربران بر اساس زبان
# AddLanguage fa .fa
# AddLanguage en .en

# اجازه‌ی دسترسی به فایل‌های مشخص
# <Files index.php>
#    Order Deny,Allow
#    Deny from all
#    Allow from 192.168.1.1
# </Files>

# انتقال 301
# Redirect 301 /old-page.html http://example.com/new-page.html

# بلاک کردن اسکریپت‌های مخرب
# <IfModule mod_rewrite.c>
#     RewriteEngine On
#     RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#     RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#     RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
#     RewriteRule ^(.*)$ index.php [F,L]
# </IfModule>

# جلوگیری از دسترسی مستقیم به فایل‌های محتویات با استفاده از htaccess
<FilesMatch "\.(zip|rar|iso)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# اجازه‌دهی به دسترسی از موتور‌های جستجو
<Files robots.txt>
    Allow from all
    Satisfy All
</Files>

# جلوگیری از دسترسی به فایل‌های خاص با استفاده از IP ها
<FilesMatch "\.(pdf|doc|xls)$">
    Order Deny,Allow
    Deny from all
    Allow from 192.168.1.1
</FilesMatch>

# افزایش سرعت بارگذاری با ذخیره‌سازی فایل‌های پرسرعت در حافظه‌ی موقت
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType application/pdf A604800
    ExpiresByType application/x-shockwave-flash A604800
    ExpiresByType image/x-icon A604800
    ExpiresByType image/jpg A604800
    ExpiresByType image/jpeg A604800
    ExpiresByType image/png A604800
    ExpiresByType image/gif A604800
    ExpiresByType application/x-javascript A604800
    ExpiresByType text/javascript A604800
    ExpiresByType text/css A604800
</IfModule>

# جلوگیری از هرگونه دستکاری فایل‌های .htaccess
<Files .htaccess>
    Order Allow,Deny
    Deny from all
</Files>

# اجازه‌ی دسترسی به همه برای حالت پیش‌فرض
<Directory "/">
    Require all granted
</Directory>

# محدود کردن متدهای HTTP معتبر
<LimitExcept GET POST HEAD>
    deny from all
</LimitExcept>

# جلوگیری از حملات HTTP Referer
SetEnvIfNoCase Referer "^https?://([^/]+\.example\.com|[^/]+\.(example|test)\.com|www\.example\.com)$" trusted_referer
Order Deny,Allow
Deny from all
Allow from env=trusted_referer

# جلوگیری از حملات کراس-سایت
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# جلوگیری از حملات اجرای فایل‌های مخرب
<FilesMatch "\.(php|php4|php5|php7|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$">
    Require all denied
</FilesMatch>

# اجازه‌ی دسترسی به تمام فایل‌ها
<Files "*">
    Require all granted
</Files>

# جلوگیری از دسترسی مستقیم به فایل‌های .htaccess
<Files .htaccess>
    Require all denied
</Files>

# جلوگیری از دسترسی مستقیم به فایل‌های کانفیگ
<FilesMatch "(\.bak|\.config|\.sql|\.ini|\.log|\.sh|\.sql|\.swp|\.dist|DEPRECATED|COMPOSER)$">
    Require all denied
</FilesMatch>

# جلوگیری از دسترسی مستقیم به فایل‌های .htaccess
<Files .htaccess>
    Require all denied
</Files>

# جلوگیری از نمایش لیست دایرکتوری
Options -Indexes

# جلوگیری از حملات اجرای فایل‌های مخرب
<FilesMatch "\.(php|php4|php5|php7|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$">
    Require all denied
</FilesMatch>

# محدود کردن متدهای HTTP معتبر
<LimitExcept GET POST HEAD>
    deny from all
</LimitExcept>

# اجازه‌ی دسترسی به تمام فایل‌ها
<Files "*">
    Require all granted
</Files>

# جلوگیری از حملات کراس-سایت
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# اجازه‌ی دسترسی به فایل‌های مشخص
# <Files index.php>
#    Require ip 192.168.1.1
# </Files>

# تنظیم فایل خطا
ErrorDocument 403 /error_pages/403.html
ErrorDocument 404 /error_pages/404.html
ErrorDocument 500 /error_pages/500.html

# جلوگیری از دسترسی مستقیم به فایل‌های .htaccess
<Files .htaccess>
    Require all denied
</Files>

# جلوگیری از نمایش لیست دایرکتوری
Options -Indexes

# جلوگیری از حملات اجرای فایل‌های مخرب
<FilesMatch "\.(php|php4|php5|php7|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$">
    Require all denied
</FilesMatch>

# محدود کردن متدهای HTTP معتبر
<LimitExcept GET POST HEAD>
    deny from all
</LimitExcept>

# اجازه‌ی دسترسی به تمام فایل‌ها
<Files "*">
    Require all granted
</Files>

# جلوگیری از حملات کراس-سایت
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# اجازه‌ی دسترسی به فایل‌های مشخص
# <Files index.php>
#    Require ip 192.168.1.1
# </Files>

# تنظیم فایل خطا
ErrorDocument 403 /error_pages/403.html
ErrorDocument 404 /error_pages/404.html
ErrorDocument 500 /error_pages/500.html

# محدودیت‌هایی برای منابع دانلود
<FilesMatch "\.(zip|rar|iso|pdf)$">
    Require all granted
</FilesMatch>

# افزایش حداکثر اندازه فایل قابل آپلود
php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value memory_limit 128M
php_value max_execution_time 300
php_value max_input_time 300

# جلوگیری از دسترسی مستقیم به فایل‌های .htaccess
<Files .htaccess>
    Require all denied
</Files>

# جلوگیری از نمایش لیست دایرکتوری
Options -Indexes

# جلوگیری از حملات اجرای فایل‌های مخرب
<FilesMatch "\.(php|php4|php5|php7|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$">
    Require all denied
</FilesMatch>

# محدود کردن متدهای HTTP معتبر
<LimitExcept GET POST HEAD>
    deny from all
</LimitExcept>

# اجازه‌ی دسترسی به تمام فایل‌ها
<Files "*">
    Require all granted
</Files>

# جلوگیری از حملات کراس-سایت
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# اجازه‌ی دسترسی به فایل‌های مشخص
# <Files index.php>
#    Require ip 192.168.1.1
# </Files>

# تنظیم فایل خطا
ErrorDocument 403 /error_pages/403.html
ErrorDocument 404 /error_pages/404.html
ErrorDocument 500 /error_pages/500.html

# محدودیت‌هایی برای منابع دانلود
<FilesMatch "\.(zip|rar|iso|pdf)$">
    Require all granted
</FilesMatch>

# افزایش حداکثر اندازه فایل قابل آپلود
php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value memory_limit 128M
php_value max_execution_time 300
php_value max_input_time 300

# برای جلوگیری از مستقیم دسترسی به فایل‌های .htaccess
<Files .htaccess>
    Order allow,deny
    Deny from all
</Files>

# جلوگیری از نمایش لیست دایرکتوری
Options -Indexes

# فعال‌سازی تفکیک کاربران بر اساس زبان
# AddLanguage fa .fa
# AddLanguage en .en

# اجازه‌ی دسترسی به فایل‌های مشخص
# <Files index.php>
#    Order Deny,Allow
#    Deny from all
#    Allow from 192.168.1.1
# </Files>

# انتقال 301
# Redirect 301 /old-page.html http://example.com/new-page.html

# بلاک کردن اسکریپت‌های مخرب
# <IfModule mod_rewrite.c>
#     RewriteEngine On
#     RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#     RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#     RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
#     RewriteRule ^(.*)$ index.php [F,L]
# </IfModule>

# جلوگیری از دسترسی مستقیم به فایل‌های محتویات با استفاده از htaccess
<FilesMatch "\.(zip|rar|iso)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# اجازه‌دهی به دسترسی از موتور‌های جستجو
<Files robots.txt>
    Allow from all
    Satisfy All
</Files>

# جلوگیری از دسترسی به فایل‌های خاص با استفاده از IP ها
<FilesMatch "\.(pdf|doc|xls)$">
    Order Deny,Allow
    Deny from all
    Allow from 192.168.1.1
</FilesMatch>

# افزایش سرعت بارگذاری با ذخیره‌سازی فایل‌های پرسرعت در حافظه‌ی موقت
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType application/pdf A604800
    ExpiresByType application/x-shockwave-flash A604800
    ExpiresByType image/x-icon A604800
    ExpiresByType image/jpg A604800
    ExpiresByType image/jpeg A604800
    ExpiresByType image/png A604800
    ExpiresByType image/gif A604800
    ExpiresByType application/x-javascript A604800
    ExpiresByType text/javascript A604800
    ExpiresByType text/css A604800
</IfModule>

# جلوگیری از هرگونه دستکاری فایل‌های .htaccess
<Files .htaccess>
    Order Allow,Deny
    Deny from all
</Files>
  1. ورود به صفحه فارسی