服务器apahce配置vhosts实现多站点的方法
- 5024
- Linux
- 3
- super_dodo
- 2015/05/20
紧接上一篇
搭建apahce服务器出现403的解决方法,防火墙开放80端口
这个时候你需要配置你的网站的相关域名和项目了,当你服务器很多的时候,你可以一台服务器放一个站点,可略去此步骤。但是对于大多数用户来说,一台服务器会设置多个站点,或者多个二级域名。
这时候我们常用的修改httpd-vhosts.conf文件,实现多站点。开始之前请先完善你的配置文件 httpd.conf。
1.搜索和 vhosts相关的内容,并开启这两行 LoadModule vhost_alias_module modules/mod_vhost_alias.so # Virtual hosts Include conf/extra/httpd-vhosts.conf 2.开启rewrite模块 LoadModule rewrite_module modules/mod_rewrite.so 3.如果谨慎一点的话,搜索系统文件(C:\Windows\System32\drivers\etc\hosts)hosts文件 127.0.0.1 localhost 127.0.0.1 www.dodobook.net
开启完毕重启Apache服务,之后来配置httpd-vhosts.conf(D:\wamp\bin\apache\apache2.4.18\conf\extra\httpd-vhosts.conf
)文件,直接上代码
#.......把该文件里面的其他项目都屏蔽了.. #<VirtualHost *:80> # ServerAdmin webmaster@dummy-host2.example.com # DocumentRoot "c:/Apache24/docs/dummy-host2.example.com" # ServerName dummy-host2.example.com # ErrorLog "logs/dummy-host2.example.com-error.log" # CustomLog "logs/dummy-host2.example.com-access.log" common #</VirtualHost> <VirtualHost *:80> DocumentRoot "c:/wamp/www" ServerName localhost <Directory "c:/wamp/www"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot "c:\wamp\www\www.dodobook.net" ServerName www.dodobook.net ServerAlias www.dodobook.net ErrorLog "logs/www.dodobook.net-error.log" CustomLog "logs/www.dodobook.net-access.log" common <Directory "c:\wamp\www\www.dodobook.net"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> RewriteEngine On RewriteRule ^(/assets|/css|/images|/themes|/file|/ueditor|/js|/favicon\.ico|/crossdomain\.xml|/upload).* $0 [L] RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^([^\?]*)$ /index.php$1?%1 [L] </VirtualHost>
至于里面的日志记录方面的功能,已经rewrite规则请另行查阅,你也可以选择屏蔽不同的部分。我使用的Yii框架。
此时你已经大功告成了。去远程或者本地访问一下你设置的域名吧。域名需提前解析到该IP,使用cmd的ping可以检测.
题外话:这个时候你会发现其中的
# AllowOverride none
# Require all denied
# Options FollowSymLinks
# AllowOverride None
# Order deny,allow
# allow from all
#
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
#
# 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.4/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:
# AllowOverride FileInfo AuthConfig Limit
#
#AllowOverride all
#
# Controls who can get stuff from this server.
#
# onlineoffline tag - don't remove
# Require local
# Order Deny,Allow
# Deny from all
# Allow from all
#
[/php]
相关阅读:
激活windows Server 2008 r2服务器的方法和工具
安装wampserver2.5时 没有找到MSVCR110.dll的解决办法
搭建apahce服务器出现403的解决方法,防火墙开放80端口
服务器apahce配置vhosts实现多站点的方法
无畏并不能带给你力量,畏惧死亡才会为活下来提供的最大力量
相关阅读
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例
热门文章
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例
最新文章
- 通过Google API客户端访问Google Play帐户报告PHP库
- PHP执行文件的压缩和解压缩方法
- 消息中间件MQ与RabbitMQ面试题
- 如何搭建一个拖垮公司的技术架构?
- Yii2中ElasticSearch的使用示例