← Back to Apache Course | Chapter 2: Configuration Basics | Lesson 1 of 4

httpd.conf फ़ाइल

httpd.conf Apache की main configuration file है -- वह जगह जहाँ आप Apache को बताते हैं कि किस port पर सुनना है, आपकी website की files कहाँ हैं, और इसे कैसे behave करना चाहिए। इस course का बाकी लगभग सब कुछ असल में इस file (या इसके include किए गए files) को edit करने के बारे में ही है।

इसे कहाँ ढूंढें

exact path आपके OS पर depend करता है: RHEL/CentOS पर /etc/httpd/conf/httpd.conf, Ubuntu/Debian पर /etc/apache2/apache2.conf (plus इसके include किए गए files), और एक XAMPP Windows install पर C:\xampp\apache\conf\httpd.conf। खासकर Ubuntu पर, apache2.conf ज़्यादातर बस दूसरी files को Include करता है -- असली interesting configuration ports.conf, sites-enabled/, और mods-enabled/ में बंटी होती है।

Core Directives

मुट्ठी भर directives file का ज़्यादातर हिस्सा बनाते हैं। ServerRoot वह base directory set करता है जिससे Apache दूसरे relative paths treat करता है। Listen set करता है कि Apache किस port(s) पर connections accept करे। DocumentRoot वह directory set करता है जहाँ से किसी given site की files serve होती हैं। ServerAdmin कुछ error pages पर दिखने वाला एक contact email set करता है। ServerName वह hostname set करता है जिससे Apache खुद को identify करता है।

Include और IncludeOptional

एक बड़ी file की जगह, Apache आपको Include path/to/file.conf या पूरी directory के लिए Include conf.d/*.conf से configuration को कई files में बांटने देता है। IncludeOptional वही काम करता है लेकिन अगर pattern से कोई files match न हों तो error नहीं देता। distros Virtual Hosts और modules को एक monolithic config की बजाय अपनी अलग files में structure ऐसे ही करते हैं।

Reload करने से पहले Config Test करना

Apache एक syntax checker देता है जिसे हर reload से पहले चलाना चाहिए: apachectl configtest (या Debian/Ubuntu पर apache2ctl configtest, या सीधे httpd -t)। यह हर included file parse करता है और actually server को restart किए बिना "Syntax OK" या problem की exact line report करता है।

Note: हर systemctl reload apache2 से पहले apachectl configtest को आदत बना लें -- यहाँ एक typo पकड़ने में दो सेकंड लगते हैं; Apache के live server पर restart करने से मना करने के बाद इसे पकड़ने में कहीं ज़्यादा समय लगता है।

उदाहरण: Core directives in httpd.conf

apacheconf
ServerRoot "/etc/httpd"
Listen 80

ServerAdmin [email protected]
ServerName example.com

DocumentRoot "/var/www/html"

# Pull in additional config split across other files
IncludeOptional conf.d/*.conf
{# Flagged by hand after confirming a runner can't handle this example (a shell command / go.mod file stored as a TopicExample, a language feature the configured runner version doesn't support, or output that blows a runner's sandbox limit) -- see TopicExample.norun. Never render the run button for these, regardless of language, since it would just fail at execute_code (or worse, hang the Judge0 queue on a submission that can never finish cleanly). #}

⚠️ This example can't run in the browser editor. Try it in your own local environment instead.

{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. distro के लिए गलत file edit करना -- जैसे Ubuntu पर एक single httpd.conf की उम्मीद करना जब असली per-site config sites-available/ में रहता है, या RHEL पर इसका उल्टा।
  2. पहले configtest चलाए बिना config change के बाद Apache reload करना, ताकि एक typo सिर्फ syntax check fail करने की बजाय पूरा server down कर दे।
  3. यह न समझना कि directives inherited होते हैं और file में बाद में (या किसी included file में) ज़्यादा specific contexts से override हो सकते हैं -- order और scope दोनों मायने रखते हैं।
🔒

Chapter Quiz — Complete all 4 topics to unlock

0/4 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.