CentOS系统下Apache配置多域名或多端口映射的方法
前提
CentOS下Apache默认网站根目录为/var/www/html,假如我默认存了一个CI项目在html文件夹里,同时服务器的外网IP为ExampleIp,因为使用的是MVC框架,Apache需开启重定向功能。
方法如下
/etc/httpd/conf/httpd.conf文件配置如下:
DocumentRoot"/var/www/html/CI"
<Directory/> OptionsFollowSymLinks AllowOverrideAll </Directory>
<Directory"/var/www/html/CI"> # #PossiblevaluesfortheOptionsdirectiveare"None","All", #oranycombinationof: #IndexesIncludesFollowSymLinksSymLinksifOwnerMatchExecCGIMultiViews # #Notethat"MultiViews"mustbenamed*explicitly*---"OptionsAll" #doesn'tgiveittoyou. # #TheOptionsdirectiveisbothcomplicatedandimportant.Pleasesee #http://httpd.apache.org/docs/2.2/mod/core.html#options #formoreinformation. # OptionsIndexesFollowSymLinks # #AllowOverridecontrolswhatdirectivesmaybeplacedin.htaccessfiles. #Itcanbe"All","None",oranycombinationofthekeywords: #OptionsFileInfoAuthConfigLimit # AllowOverrideAll # #Controlswhocangetstufffromthisserver. # Orderallow,deny Allowfromall </Directory>
配置完使用“servicehttpdrestart”重启Apache,那么直接在浏览器里输入http://ExampleIp,就直接映射到/var/www/html/CI文件夹里了
1、配置多域名映射。假设需要映射www.website1.com和www.website1.com这两个域名,在文档httpd.conf最后添加
NameVirtualHost*:80 <VirtualHost*:80> DocumentRoot/var/www/html/website1 ServerNamehttp://www.website1.com </Virtualhost> <Directory"/var/www/html/website1"> OptionsIndexesFollowSymLinks AllowOverrideAll Orderallow,deny Allowfromall </Directory> <VirtualHost*:80> DocumentRoot/var/www/html/website1 ServerNamehttp://website1.com </Virtualhost> <Directory"/var/www/html/website1"> OptionsIndexesFollowSymLinks AllowOverrideAll Orderallow,deny Allowfromall </Directory> <VirtualHost*:80> DocumentRoot/var/www/html/website2 ServerNamehttp://www.website2.com </Virtualhost> <Directory"/var/www/html/website2"> OptionsIndexesFollowSymLinks AllowOverrideAll Orderallow,deny Allowfromall </Directory> <VirtualHost*:80> DocumentRoot/var/www/html/website2 ServerNamehttp://website2.com </Virtualhost> <Directory"/var/www/html/website2"> OptionsIndexesFollowSymLinks AllowOverrideAll Orderallow,deny Allowfromall </Directory>
website1和website2为工程目录.配置完使用“servicehttpdrestart”重启Apache
2、配置多端口映射。
2.2、首先需要监听端口,在文档httpd.conf的Listen80下添加需要监听的端口,举例为8080
Listen80 Listen8080
2.2、在文档最后添加端口映射功能
<VirtualHostExampleIp:8080> DocumentRoot/var/www/html/website3 ServerNameExampleIp:8080 </VirtualHost> <Directory"/var/www/html/website3"> OptionsIndexesFollowSymLinks AllowOverrideAll Orderallow,deny Allowfromall </Directory>
website3为工程目录.配置完使用“servicehttpdrestart”重启Apache
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。