一个服务器的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.cnblogs.com/wanyong-wy/p/9257787.html