Академический Документы
Профессиональный Документы
Культура Документы
SelectLanguage
T ranslat e
Poweredby
T ranslat e DidYouKnow?
WearepleasedtoannouncetheLaunchofourNewSection"TecMintAsk"
AskaQuestion
ApacheVirtualHosting:IPBasedandNameBasedVirtualHostsin RHEL/CentOS/Fedora
ByTarunikaShrivastavaUnder:Apache,WebServersOn:January6,2014 DownloadYourFreeeBooksNOW10FreeLinuxeBooksforAdministrators AsweallareawarethatApache isaverypowerful,highlyflexibleandconfigurableWebserverforNix OS.Hereinthistutorial,wearegoingtodiscussonemorefeatureofApache whichallowsustohostmore thanonewebsiteonasingleLinuxmachine.ImplementingvirtualhostingwithApachewebservercanhelp youtosavecostsyouareinvestingonyourservermaintenanceandtheiradministration.
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a
1/17
4/20/2014
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a
2/17
4/20/2014
NameBasedVirtualHosting
IPBasedVirtualHosting
WiththeIPbasedvirtualhosting,youcanassignaseparateIPforeachdomainonasingleserver,theseIPs canbeattachedtotheserverwithsingleNICcardsandaswellasmultipleNICs.
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a
3 /17
4/20/2014
HowtoSetupIPBasedandNameBasedApacheVirtualHosts
BeforesettingupvirtualhostingwithApache ,yoursystemmusthaveApacheWebsoftwareinstalled.ifnot, installitusingdefaultpackageinstallercalledyum.
[ r o o t @ t e c m i n t~ ] #y u mi n s t a l lh t t p d
SearchforNameVirtualHostanduncommentthislinebyremovingthe# signinfrontofit.
N a m e V i r t u a l H o s t
NextaddtheIPwithpossibleinwhichyouwanttoreceiveApacherequests.Afterthechanges,yourfile shouldlooklikethis:
N a m e V i r t u a l H o s t1 9 2 . 1 6 8 . 0 . 1 0 0 : 8 0
4/20/2014
Youarefreetoaddasmanydirectivesyouwanttoaddinyourdomainsvirtualhostsection.Whenyouare donewithchangesinhttpd.conffile,pleasecheckthesyntaxoffileswithfollowingcommand.
[ r o o t @ t e c m i n t~ ] #h t t p dt S y n t a xO K
Nowitstimetocreateatestpagecalledindex.htmladdsomecontenttothefilesowewillhavesomething tocheckit,whentheIPcallsthevirtualhost.
[ r o o t @ t e c m i n t~ ] #v i/ v a r / w w w / h t m l / e x a m p l e 1 . c o m / i n d e x . h t m l < h t m l > < h e a d > < t i t l e > w w w . e x a m p l e 1 . c o m < / t i t l e > < / h e a d > < b o d y > < h 1 > H e l l o ,W e l c o m et ow w w . e x a m p l e 1 . c o m . < / h 1 > < / b o d y > < / h t m l > [ r o o t @ t e c m i n t~ ] #v i/ v a r / w w w / h t m l / e x a m p l e 2 . c o m / i n d e x . h t m l < h t m l > < h e a d > < t i t l e > w w w . e x a m p l e 2 . c o m < / t i t l e > < / h e a d > < b o d y > < h 1 > H e l l o ,W e l c o m et ow w w . e x a m p l e 2 . c o m . < / h 1 > < / b o d y > < / h t m l >
Onceyouredonewithit,youcantestthesetupbyaccessingboththedomainsinabrowser.
h t t p : / / w w w . e x a m p l e 1 . c o m h t t p : / / w w w . e x a m p l e 2 . c o m Preview:www.example1.com
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a 5 /17
4/20/2014
VirtualHosting:www.example1.com
Preview:www.example2.com
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a
6/17
4/20/2014
VirtualHosting:www.example2.com SetupIPBasedVirtualHostingLinux TosetupIPbasedvirtualhosting,youmusthavemorethanoneIPaddress /Portassignedtoyourserveror yourLinuxmachine. ItcanbeonasingleNICcard,Forexample:eth0:1,eth0:2,eth0:3 soforth.MultipleNICcardscanalso beattached.IfyoudontknowhowtocreatemultipleIPsonsingleNIC,followthebelowguide,thatwill helpyououtincreating. 1. CreateMultipleIPAddressestoOneSingleNetworkInterface PurposeofimplementingIPbasedvirtualhosting istoassignimplementingforeachdomainandthat particularIPwillnotbeusedbyanyotherdomain. ThiskindofsetuprequiredwhenawebsiteisrunningwithSSLcertificate(mod_ssl)orondifferentports andIPs.AndYoucanalsorunmultipleinstancesofApacheonasinglemachine.TochecktheIPsattachedin yourserver,pleasecheckitusingifconfigcommand.
r o o t @ t e c m i n t~ ] #i f c o n f i g SampleOutput
e t h 0
L i n ke n c a p : E t h e r n e t H W a d d r0 8 : 0 0 : 2 7 : 4 C : E B : C E i n e ta d d r : 1 9 2 . 1 6 8 . 0 . 1 0 0 B c a s t : 1 9 2 . 1 6 8 . 0 . 2 5 5 M a s k : 2 5 5 . 2 5 5 . 2 5 5 . 0 i n e t 6a d d r :f e 8 0 : : a 0 0 : 2 7 f f : f e 4 c : e b c e / 6 4S c o p e : L i n k U PB R O A D C A S TR U N N I N GM U L T I C A S T M T U : 1 5 0 0 M e t r i c : 1
7/17
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a
4/20/2014
R Xp a c k e t s : 1 7 5 5 0e r r o r s : 0d r o p p e d : 0o v e r r u n s : 0f r a m e : 0 T Xp a c k e t s : 1 5 1 2 0e r r o r s : 0d r o p p e d : 0o v e r r u n s : 0c a r r i e r : 0 c o l l i s i o n s : 0t x q u e u e l e n : 1 0 0 0 R Xb y t e s : 1 6 5 6 5 9 8 3( 1 5 . 7M i B ) T Xb y t e s : 2 4 0 9 6 0 4( 2 . 2M i B ) e t h 0 : 1 L i n ke n c a p : E t h e r n e t H W a d d r0 8 : 0 0 : 2 7 : 4 C : E B : C E i n e ta d d r : 1 9 2 . 1 6 8 . 0 . 1 0 1 B c a s t : 1 9 2 . 1 6 8 . 0 . 2 5 5 M a s k : 2 5 5 . 2 5 5 . 2 5 5 . 0 U PB R O A D C A S TR U N N I N GM U L T I C A S T M T U : 1 5 0 0 M e t r i c : 1 L i n ke n c a p : L o c a lL o o p b a c k i n e ta d d r : 1 2 7 . 0 . 0 . 1 M a s k : 2 5 5 . 0 . 0 . 0 i n e t 6a d d r :: : 1 / 1 2 8S c o p e : H o s t U PL O O P B A C KR U N N I N G M T U : 1 6 4 3 6 M e t r i c : 1 R Xp a c k e t s : 1 7 7 5e r r o r s : 0d r o p p e d : 0o v e r r u n s : 0f r a m e : 0 T Xp a c k e t s : 1 7 7 5e r r o r s : 0d r o p p e d : 0o v e r r u n s : 0c a r r i e r : 0 c o l l i s i o n s : 0t x q u e u e l e n : 0 R Xb y t e s : 3 4 1 6 1 0 4( 3 . 2M i B ) T Xb y t e s : 3 4 1 6 1 0 4( 3 . 2M i B )
l o
SearchforwordListen,YoufindasectionwheretheshortdescriptionaboutListendirectiveiswritten.In thatsection,commenttheoriginallineandwriteyourowndirectivebelowthatline.
#L i s t e n8 0 L i s t e n1 9 2 . 1 6 8 . 0 . 1 0 0 : 8 0
Now,createaVirtualhostsectionsforboththedomains.Gothebottomofthefileandaddthefollowing virtualdirectives.
V i r t u a l H o s t1 9 2 . 1 6 8 . 0 . 1 0 0 : 8 0 > S e r v e r A d m i nw e b m a s t e r @ e x a m p l e 1 . c o m D o c u m e n t R o o t/ v a r / w w w / h t m l / e x a m p l e 1 S e r v e r N a m ew w w . e x a m p l e 1 . c o m E r r o r L o gl o g s / w w w . e x a m p l e 1 . c o m e r r o r _ l o g T r a n s f e r L o gl o g s / w w w . e x a m p l e 1 . c o m a c c e s s _ l o g < / V i r t u a l H o s t > < V i r t u a l H o s t1 9 2 . 1 6 8 . 0 . 1 0 1 : 8 0 > S e r v e r A d m i nw e b m a s t e r @ e x a m p l e 2 . c o m D o c u m e n t R o o t/ v a r / w w w / h t m l / e x a m p l e 2 S e r v e r N a m ew w w . e x a m p l e 2 . c o m E r r o r L o gl o g s / w w w . e x a m p l e 2 . c o m e r r o r _ l o g T r a n s f e r L o gl o g s / w w w . e x a m p l e 2 . c o m a c c e s s _ l o g < / V i r t u a l H o s t >
Now,sinceyouhavemodifiedmainApacheconffile,youneedtorestartthehttpservicelikebelow.
[ r o o t @ t e c m i n t~ ] #s e r v i c eh t t p dr e s t a r t S t o p p i n gh t t p d : S t a r t i n gh t t p d : [ O K ] [ O K ]
TestyourIPbasedVirtualhostingsetupbyaccessingtheURLs onwebbrowserasshownbelow.
h t t p : / / w w w . e x a m p l e 1 . c o m
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a 8 /17
4/20/2014
h t t p : / / w w w . e x a m p l e 2 . c o m
ReferenceLinks
ApacheVirtualHostDocumentation IllbeagaincomewithsomeotherApachetipsandtrickinmyfuturearticles,tillthenStayGeekyand connectedtoTecmint.com.Donotforgettoleaveyoursuggestionsaboutthearticleinourcommentsection below.
Bio LatestPosts
TarunikaShrivastava
IamalinuxserveradminandlovetoplaywithLinuxandallotherdistributionsofit.Iam workingasSystemEngineerwithaWebHostingCompany.
LinuxServices&FreeWordPressSetup
150
Like
25
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u a
9/17
4/20/2014
6
Share
12 comments
InterviewQuestion FreeLinux AntivirusSoftware Certificate
AntivirusSoftware Certificate
Freeebookpdf
Athomework
FreeSoftware
InterviewQuestion SignIn
FreeSoftware
Workinhome
Webhostingserver
RelatedPost(s):
1. HowtoSetupCherokee(Webserver)withPHP5(FastCGI)/MySQLSupportinUbuntu12.10 2. InstallLighttpdwithMySQL5andPHP5(PHPFPM)SupportonRHEL/CentOS6.3/5.8 3. HowtoInstallVarnishCache(WebAccelerator)inRHEL/CentOS/FedoraandUbuntu/Debian 4. 13ApacheWebServerSecurityandHardeningTips 5. InstallMod_GeoIPforApacheinRHEL/CentOS6.3/5.8 6. CreatingYourOwnWebserverandHostingAWebsitefromYourLinuxBox
12Responses
1.
2.
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u
10/17
4/20/2014
Regards RahulPatadiya Reply 3. dipanjanmukherjeesays: January6,2014at7:58pm niceone. Reply 4. ToddLyonssays: January6,2014at11:41pm Onereallyusefulapachecommandtoseewhethernamebasedoripbasedvirtualhostingisappliedto variousIP/port/defaultcombinationsistorun: httpdS Italsodoesasyntaxcheckoftheconfigfileliketdoes. Reply 5. viharisays: January6,2014at11:51pm Iwouldliketohaveamoduleforauthenticationsquidproxyusersusingawebloginform. Whenauserstriestoaccesstheinternet,firstitshouldredirecttowebloginform,thenafter authenticationonlyusersshouldaccessinternet..! Cananyoncesuggestmehowtodothis.! Reply 6. MageshMsays: January7,2014at3:04pm @satish, Thereisnooptiontolistoutdirectoryfilesexceptlsinlinuxinsteadoflistingfilesyoucanusefind commandtocheckthecorrespondingfiles. #find/namefilename Ifyouwanttocountthefilesusebelowcommands. 1)lsl|wcl(Tocountonlycurrentdirectoryfileandfolders) 2)findtypef|wcl(Tocountfileandfoldersrecursively) Reply 7. ARUNKARTHIKEsays: January27,2014at6:01pm
11/17
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u
4/20/2014
USEFULONE..BUTIAMHAVINGADOUBT.WHICHISHOWMANYVIRTUALHOSTS CANBECREATEDINAPACHEWEBSERVER.ITHINKITHASNOLIMITS.BUTIAM NOTSURE..ANYONEIFKNOWABOUTTHISPLEASEREPLYHEREORCONTACTTHRU MYIDarunkarthik29890@gmail.com. Reply TarunikaShrivastavasays: January28,2014at9:09pm HiArun, Yes,Thereisnolimit,youcanaddnnumbersofVirtualhostsaccordingtoyourserver resources.:) Reply 8. bijoyprajapatisays: February20,2014at3:24pm hostaapacheeserveronyourhostname=wwwX.example.com pchostname:desktop45.example.com path/var/www/virtual/index.html Ididalltheconfigurationcorrectly,plzfollow:.. vim/etc/httpd/conf/httpd.conf NmeVirtualHost:desktop45.example.com VirtualHostdesktop45.example.:80> ServerAdminwebmaster@wwwXexample.com DocumentRoot/var/www/virtual ServerNamewwwX.example.com ErrorLoglogs/wwwX.example.comerror_log TransferLoglogs/www.example1.comaccess_log plzhelpassoonaspossible Reply 9. Kalimsays: February21,2014at4:18pm @bijoyprajapatiFollowbelowlink http://computernetworkingnotes.com/networkadministrations/webserver.html Reply 10. suvarnasays: April9,2014at1:17pm
12/17
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u
4/20/2014
HiTarunika, Thankyouforthiswonderfullartical.Ithelpedmealottounderstandconceptsregardingvirtualhostand apachewebserver.Reallyappriciateforthis.ThankyouforTecmint. Pleasekeeppostingsuchinformativearticals:) Reply TarunikaShrivastavasays: April9,2014at11:37pm HiSuvarna, Thanksforyourgoodwords,itreallymeansalottome:) Reply
LeaveaReply
Name(Required) Mail(willnotbepublished)(Required) Website
SubmitComment
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u
13 /17
4/20/2014
BecomeAT ecMintSubscribertoreceivelatestUpdates.
EnterYourEmailAddress:) Signup!
Wine1.6.2StableReleasedInstallinRHEL,CentOSandFedora150Comments
CentOS6.4StepbyStepInstallationGuidewithScreenshots142Comments
InstallApache2.2.15,MySQL5.5.34&PHP5.5.4onRHEL/CentOS6.4/5.9&Fedora1912139 Comments
InstallCacti(NetworkMonitoring)onRHEL/CentOS6.3/5.8andFedora1712119Comments
Nagios4.0.1ReleasedInstallonRHEL/CentOS6.x/5.xandFedora19/18/17104Comments
GoogleChrome34ReleasedInstallonRHEL/CentOS6andFedora2015104Comments
::Advertise::
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u 14/17
4/20/2014
::DownloadFreeLinuxeBooks::
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u
15 /17
4/20/2014
::FollowUs::
TecMint.com
google.com/+Tecmint Tecmint:LinuxHowtos,Tutorials&Guides Follow +3,042 +1
::About::
TecMint.comisawebsitethatpublishespracticalandusefuloutoftheboxarticlesforaspirantlikeyouand me.Weseektopresentexceptional,remarkabletips,tutorials,andresourcesthatthemodernweb professionalwillappreciate.
::OurServices::
KnowMore
::Advertise::
SubmitOrder
AdvertiseNow
4/20/2014
25HardeningSecurityTipsforLinuxServers 60CommandsofLinux:AGuidefromNewbiestoSystemAdministrator 15CommandLineToolstoMonitorLinuxPerformance 5BestPracticestoSecureandProtectSSHServer 18TarCommandExamplesinLinux 20LinuxYUM(YellowdogUpdater,Modified)Commands 25UsefulBasicCommandsofAPTGETandAPTCACHE 20FunnyCommandsofLinuxorLinuxisFuninTerminal 35PracticalExamplesofLinuxFindCommand 10LinuxDistributionsandTheirTargetedUsers
file:///h om e/pu sh pen dra.sin gh /Deskt op/Apach e%20Virt u al%20H ost in g%20%20IP%20Based%20an d%20N am e%20Based%20Virt u
17/17