Reverse Proxy
အရင်ဆုံး reverse proxy အကြောင်းမပြောခင် forward proxy (or) proxy server ရဲ့ အလုပ်လုပ်ပုံကို အနည်းငယ်ပြောချင်ပါတယ်။ forward proxy ရဲ့အလုပ်လုပ်က ဆိုပါတော့ internal network မှာရှိတဲ့ clients စက် တွေက public မှာရှိတဲ့ Web Server တစ်ခုကို access လုပ်တဲ့အခါ သူတို့ရဲ့ ရှေ့မှာ internal network ထဲမှာ proxy server ခံထားမယ်ဆိုရင် ၄င်း proxy server ကိုအရင်ဖြတ်ရပါတယ်။ ၄င်း proxy server ကနေမှ access လုပ်ခွင့်ပေးမယ် မပေးဘူး ဆုံးဖြတ်ပြီး access ပေးမယ်ဆိုရင် တစ်ဖက် က Public web server ဆီ ကို client ကိုယ်စား proxy server ကနေ ဆက်သွယ်ပေးပါတယ်။ တစ်ခြားတစ်ဖက်က Public web Server ကလဲ response ပြန်တဲ့အခါ client ဆီသို့ တိုက်ရိုက်မဟုတ်ပဲ proxy ဆီကိုပဲ response ပြန်ပေးတာဖြစ်ပါတယ်။ တစ်နည်းအားဖြင့် proxy ခံထားသည့်အတွက် client နဲ့ အပြင်က web server ကြားမှာ တိုက်ရိုက် ထိတွေ့ မှုမရှိတော့ဘူးဖြစ်ပါတယ်။
Reverse Proxy ကျတော့ အဲ့ဒီ client တွေ access လုပ်ချင်တဲ့ Public Web Server ရဲ့အရှေ့ကနေ ထားပြီး အသုံးပြုတာဖြစ်ပါတယ်။ အဲ့အခါ client တွေ access လှမ်းလုပ်တဲ့အခါမှာ reverse proxy server ကိုပဲ access လုပ်လို့ရတာဖြစ်ပြီး reverse proxy ကမှ web server တွေရဲ့ ကိုယ်စား response ပြန်ပေးတာဖြစ်ပါတယ်။
Lab Setup
-----------
node02.private.com = Apache Web Server
node03.private.com = Nginx Reverse Proxy
Setup Apache Web server
အရင်ဆုံး node02 မှာ apache web server တစ်ခု setup လုပ်လိုက်ပါမယ်။ လိုအပ်တဲ့ httpd package သွင်းမယ်။
ပြီးရင် httpd service start and enable လုပ်မယ် firewall မှာ http allow လုပ်ပေးမယ်။
"/var/www/html/" မှာ index.html content တစ်ခုဆောက်ပါမယ်။ curl နဲ့ ခေါ်ကြည့်လျှင် node02 ပေါ်မှာ apache web server တစ်ခု တည်ဆောက်လို့ပြီးပါပြီ။ ထို့နောက်မှ အခု web server run ထားတဲ့ node02 ကို Nginx reverse proxy ဖြစ်တဲ့ node03 ကနေ့ ခေါ်ယူ အသုံးပြုမှာဖြစ်ပါတယ်။
Setup Nginx Reverse Proxy
အရင်ဆုံး Nginx package ကို install ပြုလုပ်ရပါမယ်။ Nginx package install လုပ်ဖို့ရာ Epel repo လိုအပ်ပါတယ်။
ထို့နောက် Nginx service start and enable လုပ်မယ် firewall မှာ allow လုပ်ပေးပါမယ်။
Edit inside at "/etc/nginx/nginx.conf"
Reverse proxy config ကို "/etc/nginx/nginx.conf" ထဲမှာ အောက်မှာ ဖော်ပြထားတဲ့အတိုင်းပြင်ရေးရပါမယ်။ အဲ့ဒီမှာ "server_name" နေရာမှာ လက်ရှိ nginx service run နေတဲ့ node03 hostname ဖြစ်ပြီး
"proxy_pass" မှာ Apache Web service run နေတဲ့ node02 url ကိုထည့်ပေးရပါမှာဖြစ်ပါတယ်။
ပြီးရင်တော့ nginx -t ဖြင့် config error ရှိမရှိ စစ်ပြီး nginx service ကို restart ချပါမယ်။
ထို့နောက်မှာတော့ curl ဖြင့် node03 (nginx reverse proxy) url ကိုခေါ်လိုက်လျှင် တစ်ဖက် node02 (apache web server) ရဲ့ web content ကို reverse proxy အသုံးပြုပြီး response ပြန်ပေးမှာဖြစ်ပါတယ်။
That's it for Setting up basic Nginx reverse proxy!!! :)
Thanks and Enjoy Reading!!!
nginx config file ထဲကဟာေတြက manual ေရးေပးရမွာလား
ReplyDeleteNot all the config need to write, some are already inside the config.
Delete