CentOS系统下Apache配置多域名或多端口映射的方法
linux  /  管理员 发布于 7年前   117
前提
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/website1ServerName 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/website1ServerName http://website1.com </Virtualhost><Directory "/var/www/html/website1">Options Indexes FollowSymLinksAllowOverride AllOrder allow,denyAllow from all</Directory><VirtualHost *:80>DocumentRoot /var/www/html/website2ServerName 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/website2ServerName http://website2.com </Virtualhost><Directory "/var/www/html/website2">Options Indexes FollowSymLinksAllowOverride AllOrder allow,denyAllow from all</Directory>
website1和website2为工程目录.配置完使用“service httpd restart”重启Apache
2、配置多端口映射。
2.2、首先需要监听端口,在文档httpd.conf的Listen 80下添加需要监听的端口,举例为8080
Listen 80Listen 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
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号