mod_proxy का उपयोग
mod_proxy Apache को requests को किसी दूसरे server पर forward करने देता है -- आमतौर पर Gunicorn, Node.js, या किसी दूसरी machine पर एक backend जैसा एक application server -- और response को वापस ऐसे handle करता है जैसे Apache ने खुद इसे generate किया हो।In this page:
Forward बनाम Reverse Proxy
एक forward proxy clients के आगे बैठता है, उनकी ओर से internet fetch करता है (जैसे एक corporate proxy)। एक reverse proxy servers के आगे बैठता है, public internet से requests लेकर उन्हें किसी backend तक forward करता है जिससे public कभी सीधे बात नहीं करती। Apache के साथ mod_proxy लगभग हमेशा दूसरे तरीके से इस्तेमाल होता है, जिसे इस course में बाद के dedicated Reverse Proxy lesson में पूरी तरह cover किया गया है।
सही Sub-Modules Enable करना
mod_proxy खुद base module है, लेकिन आपको एक protocol-specific module भी चाहिए: HTTP/HTTPS backends के लिए mod_proxy_http, या WebSocket connections के लिए mod_proxy_wstunnel। Ubuntu पर: sudo a2enmod proxy proxy_http (ज़रूरत पड़ने पर proxy_wstunnel भी add करें)।
ProxyPass और ProxyPassReverse
ProxyPass "/api/" "http://127.0.0.1:8000/" /api/ के नीचे किसी भी request को उस backend address पर forward करता है। ProxyPassReverse उल्टी direction में matching काम करता है: यह backend से वापस आने वाले Location/Set-Cookie headers को rewrite करता है ताकि वे internal की जगह public-facing URL reference करें, जो redirects और cookies के सही काम करने के लिए मायने रखता है।
एक Typical Use Case
एक बहुत common pattern: एक Python (Gunicorn/uWSGI) या Node.js app चलाना जो सिर्फ 127.0.0.1:8000 पर सुने, internet को बिल्कुल भी exposed न हो, और port 80/443 पर Apache को अकेली चीज़ बनने दें जिससे public actually बात करे -- TLS, static files, और logging handle करते हुए, फिर dynamic requests को app तक proxy करते हुए।
उदाहरण: Proxying /api/ to a local backend
ProxyPreserveHost On
ProxyPass "/api/" "http://127.0.0.1:8000/"
ProxyPassReverse "/api/" "http://127.0.0.1:8000/"
{# 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). #}
mod_proxyenable करना लेकिनmod_proxy_httpभूल जाना, ताकि plain HTTP/HTTPS proxying actually काम ही न करे।- matching ProxyPassReverse के बिना ProxyPass इस्तेमाल करना, backend से वापस आने वाले redirects या cookies को तोड़ते हुए।
- Apache से proxy करने के अलावा backend app server के port को सीधे internet पर expose करना, जिससे Apache को आगे रखने का पूरा मतलब ही खत्म हो जाता है।
Chapter Quiz — Complete all 5 topics to unlock
0/5 topics done
Complete these topics first: