温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS系统下Apache怎么配置多域名或多端口映射

发布时间:2022-04-12 15:31:52 来源:亿速云 阅读:366 作者:iii 栏目:编程语言

这篇文章主要介绍“CentOS系统下Apache怎么配置多域名或多端口映射”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“CentOS系统下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、首先需要监听端口,在文档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怎么配置多域名或多端口映射”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI