CentOS系统下Apache怎么配置多域名或多端口映射-创新互联

这篇文章主要介绍“CentOS系统下Apache怎么配置多域名或多端口映射”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“CentOS系统下Apache怎么配置多域名或多端口映射”文章能帮助大家解决问题。

目前成都创新互联已为1000多家的企业提供了网站建设、域名、网站空间网站托管运营、企业网站设计、沾化网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

前提

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
# /tupian/20230522/core.html
# 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、首先需要监听端口,在文档httpd.conf的listen 80下添加需要监听的端口,举例为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系统下Apache怎么配置多域名或多端口映射”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注创新互联行业资讯频道,小编每天都会为大家更新不同的知识点。

文章标题:CentOS系统下Apache怎么配置多域名或多端口映射-创新互联
标题URL:https://www.cdcxhl.com/article34/cscspe.html

成都网站建设公司_创新互联,为您提供手机网站建设网站排名网站改版域名注册定制开发搜索引擎优化

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

微信小程序开发