CentOS系统下Apache配置多域名或多端口映射的方法
程序员文章站
2022-04-06 23:03:57
前提
centos下apache默认网站根目录为/var/www/html,假如我默认存了一个ci项目在html文件夹里,同时服务器的外网ip为exampleip,因为使...
前提
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
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
下一篇: 黄牛肉和肉牛肉哪个好吃