溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CentOS系統(tǒng)下Apache怎么配置多域名或多端口映射

發(fā)布時間:2022-04-12 15:31:52 來源:億速云 閱讀:383 作者:iii 欄目:編程語言

這篇文章主要介紹“CentOS系統(tǒng)下Apache怎么配置多域名或多端口映射”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“CentOS系統(tǒng)下Apache怎么配置多域名或多端口映射”文章能幫助大家解決問題。

前提

centos下apache默認網站根目錄為/var/www/html,假如我默認存了一個ci項目在html文件夾里,同時服務器的外網ip為exampleip,因為使用的是mvc框架,apache需開啟重定向功能。

方法如下

/etc/httpd/conf/httpd.conf文件配置如下:

documentroot "/var/www/html/ci"
<directory />
 options followsymlinks
 allowoverride all
</directory>
<directory "/var/www/html/ci">

#
# possible values for the options directive are "none", "all",
# or any combination of:
# indexes includes followsymlinks symlinksifownermatch execcgi multiviews
#
# note that "multiviews" must be named *explicitly* --- "options all"
# doesn't give it to you.
#
# the options directive is both complicated and important. please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
 options indexes followsymlinks

#
# allowoverride controls what directives may be placed in .htaccess files.
# it can be "all", "none", or any combination of the keywords:
# options fileinfo authconfig limit
#
 allowoverride all

#
# controls who can get stuff from this server.
#
 order allow,deny
 allow from all

</directory>

配置完使用“service httpd restart”重啟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
servername http://www.website1.com 
</virtualhost>
<directory "/var/www/html/website1">
 options indexes followsymlinks
 allowoverride all
 order allow,deny
 allow from all
</directory>
<virtualhost *:80>
documentroot /var/www/html/website1
servername http://website1.com 
</virtualhost>
<directory "/var/www/html/website1">
options indexes followsymlinks
allowoverride all
order allow,deny
allow from all
</directory>
<virtualhost *:80>
documentroot /var/www/html/website2
servername http://www.website2.com 
</virtualhost>
<directory "/var/www/html/website2">
 options indexes followsymlinks
 allowoverride all
 order allow,deny
 allow from all
</directory>
<virtualhost *:80>
documentroot /var/www/html/website2
servername http://website2.com 
</virtualhost>
<directory "/var/www/html/website2">
options indexes followsymlinks
allowoverride all
order allow,deny
allow from all
</directory>

website1和website2為工程目錄.配置完使用“service httpd restart”重啟apache

2、配置多端口映射。

2.2、首先需要監(jiān)聽端口,在文檔httpd.conf的listen 80下添加需要監(jiān)聽的端口,舉例為8080

listen 80
listen 8080

2.2、在文檔最后添加端口映射功能

<virtualhost exampleip:8080>
 documentroot /var/www/html/website3
 servername exampleip:8080
</virtualhost>
<directory "/var/www/html/website3">
 options indexes followsymlinks
 allowoverride all
 order allow,deny
 allow from all
</directory>

website3為工程目錄.配置完使用“service httpd restart”重啟apache

關于“CentOS系統(tǒng)下Apache怎么配置多域名或多端口映射”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識,可以關注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI