zoukankan      html  css  js  c++  java
  • 一个服务器的Apache2.4.6配置多个域名

    进入到Apache的配置文件:cd /etc/httpd/conf/http.conf

    在后面添加:

    <VirtualHost *:80>
        # This first-listed virtual host is also the default for *:80
        ServerName www.example.com
        ServerAlias example.com 
        DocumentRoot "/var/www/html/"
    </VirtualHost>
    

     

    详细参考官网:http://httpd.apache.org/docs/2.4/vhosts/name-based.html

    附:

    <IfModule rewrite_module>
        RewriteEngine on
        RewriteRule "^/introduction/(.*)" "http://localhost:9005/introduction/$1" [R,L,P]
    </IfModule>
    

      将请求为introducton开头的转到http://localhost:9005/introduction请求

    若虚拟主机中请求localhost,就要将两者相结合:

    <VirtualHost *:80>
        # This first-listed virtual host is also the default for *:80
        ServerName www.example.com
        ServerAlias example.com
        DocumentRoot "/var/www/html/catalogs"
      <IfModule rewrite_module>
    	RewriteEngine on
    	RewriteRule "^/introduction/(.*)" "http://localhost:9005/introduction/$1" [R,L,P]
      </IfModule>
    </VirtualHost>
    

    拓展:不带WWW的域名跳转到带WWW的域名地址Apache重写规则

    第一步:Apache虚拟机配置:

    <VirtualHost *:80>
      ServerAdmin mac@xobm.com
      DocumentRoot “/var/www/www.xobm.com/”
      ServerName www.xobm.com
      ServerAlias xobm.com //这句是关键,配置别名
      ErrorLog “logs/dummy-host2.xobm.com-error.log”
      CustomLog “logs/dummy-host2.xobm.com-access.log” common
      <Directory />
        AllowOverride All
        Allow from all
      </Directory>
    </VirtualHost>
    

     第二步:HTACCESS写法

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^xobm.com [NC]
      RewriteRule ^(.*) http://www.xobm.com/ [L]
    </IfModule>
  • 相关阅读:
    Python环境搭建详解(Window平台)
    扎心了Python
    解决Git
    Android入门教程(四)
    HEXO快速搭建自己的博客
    每日Android一问等你来解答-什么是Activity的生命周期?
    如何才能够系统地学习Java并发技术?
    LeetCode刷题指南(字符串)
    学生时代的最后一个新年,请一定要做这五件事
    20位程序员关于求职的疑问,以及我给出的参考答案
  • 原文地址:https://www.cnblogs.com/wanyong-wy/p/9257787.html
Copyright © 2011-2022 走看看