الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

apachectl

Control and test the Apache web server: check the config syntax, list virtual hosts and modules. (Start and stop with systemctl.)

المستوى
امتحان RHCSA
المجموعة
الويب
يحتاج root
نعم
الحزمة
httpd
يُسمّى أيضًا
httpd

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

On RHEL, Apache runs as httpd.service; use systemctl to start, stop and reload it. apachectl configtest (= httpd -t) checks the syntax before you reload. httpd -S shows the virtual hosts as Apache understands them; httpd -M lists the loaded modules.

طريقة الكتابة

apachectl configtest | graceful | graceful-stop | start | stop | restart | fullstatus | status
httpd [-t] [-S] [-M] [-V] [-v] [-D NAME] [-f FILE] [-C DIRECTIVE]

الأجزاء الرئيسية

configtest
Check the configuration syntax (same as httpd -t).
graceful
Reload without dropping open connections (on RHEL: systemctl reload httpd).
start, stop, restart
On RHEL these call systemctl.
status, fullstatus
Status (fullstatus needs mod_status).

الخيارات 16

الأكثر استخدامًا

-t
Test the syntax (httpd).
-S
Show the parsed virtual host settings.
-M
List loaded modules.
-l
List compiled-in modules.
-L
List directives.
-V
Show version and build settings.
-v
Show the version.
-D NAME
Define a parameter for <IfDefine>; -D DUMP_VHOSTS, -D DUMP_RUN_CFG, -D DUMP_INCLUDES.
-f FILE
Use another main config file.
-C "DIRECTIVE"
Process a directive before the config.
-c "DIRECTIVE"
Process a directive after the config.
-d DIR
Another ServerRoot.
-e LEVEL
Log level at startup.
-E FILE
Startup errors to a file.
-X
Debug mode (one process, foreground).
-h
Show help.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Test the config

    apachectl configtest
    Syntax OK

    Always before a reload.

  2. 2Reload after a change

    apachectl configtest && systemctl reload httpd

    Only reloads when the syntax is OK.

  3. 3Show the virtual hosts

    httpd -S
    VirtualHost configuration:
    *:80                   is a NameVirtualHost
             default server www1.example.com (/etc/httpd/conf.d/sites.conf:5)

    Which vhost is the default and where it is defined.

  4. 4List modules

    httpd -M | grep -E 'ssl|rewrite|headers'

    Is mod_ssl loaded?

  5. 5Version

    httpd -v

    Server version and build date.

  6. 6Where are the config files?

    httpd -t -D DUMP_INCLUDES

    All included files in order.

  7. 7Status and logs

    systemctl status httpd
    tail -f /var/log/httpd/error_log

    Errors at start or for requests.

  8. 8A 403 Forbidden? Check SELinux

    ausearch -m avc -ts recent | grep httpd
    ls -Z /var/www/html

    Wrong labels are the most common reason.

  9. 9Hide version information (hardening)

    printf 'ServerTokens Prod\nServerSignature Off\n' > /etc/httpd/conf.d/security.conf
    apachectl configtest && systemctl reload httpd

    Headers show only "Apache".

  10. 10HTTPS

    dnf install -y mod_ssl; systemctl restart httpd

    Adds ssl.conf with a test certificate on port 443.

الملفات

/etc/httpd/conf/httpd.conf
Main config.
/etc/httpd/conf.d/
Extra configs and vhosts.
/etc/httpd/conf.modules.d/
Module loading.
/var/log/httpd/
Logs.
/var/www/html/
Default content.

رموز الخروج

0 :: Done (syntax OK). 1 :: Error.