- 浏览: 216404 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
foreach4:
haohao-xuexi02 写道xiang37 写道原来这么 ...
在路上 -
haohao-xuexi02:
xiang37 写道原来这么难!生活是自己的,人生很多时候,需 ...
在路上 -
xiang37:
原来这么难!生活是自己的,人生很多时候,需要拿得起,放得下。
在路上 -
xiang37:
坚强,原来那么难!
关于嘟嘟,引起的 -
heymaomao:
vi $PATH_resin/bin/httpd.sh arg ...
resin 的 java.lang.OutOfMemoryError: PermGen space 解决办法
在Apache设置虚拟主机
Setting up a virtual host in the Apache web server is not exactly a PHP topic, but many PHP developers use the Apache web server to test web pages on their development machine.建立一个在Apache Web服务器的虚拟主机是不完全是一个PHP的话题,但是许多PHP开发人员使用Apache Web服务器,以测试他们的开发机器上的网页。
There is a lot of information around on how to do this, but the first time I tried it, I found the existing information to be more confusing than helpful.有一个要做到这一点很多资料市内如何,但我第一次试了一下,我发现了现有的信息更有助于混乱比。 Hopefully, this page will simplify the process a bit.我们希望,此网页将简化程序一点。 Please note that this information pertains to setting up a virtual host in Apache on a Windows machine for use as a local testing server.请注意,此信息关于设立作为测试服务器上的本地虚拟主机在Apache上使用的Windows机器。 Setting up a virtual host for an actual production server is beyond the scope of this article and you should refer to the official Apache documentation for that.实际生产中设置一个虚拟主机服务器超出了本文的范围,这一点,你应该参考官方Apache文件这样做的。
Configuring Apache配置Apache
The first file we'll need to edit is the Apache httpd.conf
file.第一个文件,我们需要修改是Apache httpd.conf
文件。 If you installed the Apache software using the download from the Apache web site , you should have a menu item that will open this file for editing.如果你安装了Apache软件下载使用从Apache网站 ,你应该有一个菜单项,将打开该文件进行编辑。 Click Start->Programs->Apache HTTP Server->Configure Apache Server->Edit the Apache httpd.conf Configuration File.单击开始->“程序-> Apache的HTTP服务器>”配置Apache服务器->“编辑Apache的httpd.conf配置文件。 If you don't have that start menu item, start your text editor and open the file.如果你没有这样的启动菜单项,启动文本编辑器并打开该文件。 It will be in a sub-folder named conf of your Apache folder.这将是在一个子文件夹命名为你的Apache conf文件夹。 For example, mine is here:例如,我是在这里:
C:\Program Files\Apache Group\Apache\conf\httpd.conf
Notes for Apache Server Versions Since 2.2为Apache Server版本说明自2.2
Configuration配置
Note that Apache changed the preferred method for configuring the Apache server with the release of Apache 2.2.请注意,改变了Apache的配置与2.2版本的Apache Apache服务器的首选方法。 For versions beginning with 2.2, the peferred configuration is more modular.对于版本2.2开始,peferred配置更模块化。 Setting up a virtual host as described here will still work with the newer versions, but to follow the modular approach, the editing of httpd.conf is only to uncomment (remove the # from the beginning of the following line:建立一个虚拟主机描述这里将仍然使用较新的版本,而是要按照模块化的方式,编辑httpd.conf的唯一的注释(删除#从以下行的开头:
#Include conf/extra/httpd-vhosts.conf
Everything else is entered in the file httpd-vhosts.conf
, which will be located in the extra
folder below the below the folder containing httpd.conf
.其他一切都在文件中输入httpd-vhosts.conf
,这将是位于extra
包含文件夹下面的文件夹下httpd.conf
。 As mentioned, the method described here will still work.如前所述,这里描述的方法仍然可以工作。
Security安全
Version 2.2 also changed some of the default security configuration parameters. 2.2版本还改变了一些默认的安全配置参数。 To set things up the way you'll need them, you'll need to add the following block to either your httpd.conf file, just above the virtual hosts, or to your httpd-vhosts.conf file:要设置方式,您将需要他们的东西,你需要添加以下块要么你的httpd.conf文件,上面的虚拟主机,或到您的httpd - vhosts.conf文件:
<Directory "C:\ My Sites "> <目录"C:\我的网站"> Order Deny,Allow为了拒绝,允许 Allow from all允许从所有 </Directory> </目录>The above assumes you're using the directory structure described below.上述假设您正在使用的目录结构如下所述。 Adjust that as necessary to reflect your actual directory.调整是必要的,以反映实际的目录。
Now, for this example, we'll assume that you have your web sites located in a folder on your C drive called My Sites.现在,在这个例子中,我们将假设你有你的网站在C盘上的一个文件夹叫我的网站。 Each web site has a sub-folder of its own under that folder, like this:每个网站有它自己的子下像这样的文件夹,文件夹:
C:\My Sites\Site1 ç:\我的网站\站点1 C:\My Sites\Site2 ç:\我的网站\站点2
Say also, for this example, that the domains for the two sites are site1.com and site2.com.也说,在这个例子中,这两个网站的域名是site1.com和site2.com。 We're going to set up virtual hosts for those two sites using the domain names site1.local and site2.local.我们要成立这两个使用域名site1.local和site2.local网站的虚拟主机。 That way, you'll be able to tell at a glance whether you're looking at the live site, or your testing site.这样,您就可以一眼就能知道您是否正在寻找在现场站点或您的试验场。
In reality, you can call the domains anything you want.在现实中,你可以调用任何你想要的域名。 You could just as easily name them microsoft.monkeybutt and ibm.greentambourine.你可以很容易地把它们命名为microsoft.monkeybutt和ibm.greentambourine。 I choose to use the convention of using the same domain name along with the .local TLD to simplify and minimize the typing needed to switch between the live site and the testing site.我选择使用一起使用。本地顶级域名相同的域名,简化和减少所需的生活之间切换站点和测试站点键入该公约。 The only important point, and it's really important, is that you NEVER use an actual, real, live domain name.唯一重要的一点,这真的很重要,是你千万不要用实际的,真正的,活的域名。 If you used, for example, site1.com for the local virtual host, you would never be able to actually reach the live site.如果你使用,例如,主机site1.com本地虚拟的,你将永远无法真正到达现场直播。 All requests for the live site would be re-directed to your local virtual host.该活动站点的所有请求将被重新导向到您的本地虚拟主机。
Go to the very bottom of your httpd.conf file in your text editor.到最底层的httpd.conf文件在文本编辑器。 You should see an example of a virtual host there.你应该看到一个虚拟主机有例子。 Each line of that example will begin with an octothorpe (#).每个生产线将于这个例子用井号(#)。 The octothorpe character marks the line as a comment, so the example is not executed.该井号字符标记为一个注释行,所以这个例子是不会被执行。 Add the following lines below that example:下面这个例子中,添加以下几行:
NameVirtualHost 127.0.0.1 NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1> <VirtualHost 127.0.0.1> DocumentRoot "C:\My Sites\Site1"的DocumentRoot的“C:\我的网站\站点1” ServerName site1.local服务器名site1.local </VirtualHost> </虚拟主机> <VirtualHost 127.0.0.1> <VirtualHost 127.0.0.1> DocumentRoot "C:\My Sites\Site2"的DocumentRoot的“C:\我的网站\站点2” ServerName site2.local服务器名site2.local </VirtualHost> </虚拟主机>
That's all you need to do!这就是你需要做的! Save and close the file.保存并关闭该文件。 That will tell the Apache server everything it needs to know in order for it to serve the pages using the domain names site1.local and site2.local.这将告诉Apache服务器它需要的一切,为了知道它的网页服务使用的域名site1.local和site2.local。 One note is that, in the above example, we have a space in the path.一个值得注意的是,在上述例子中,我们有一个路径中的空间。 Because of that, we put quotation marks around the document root directory.正因为如此,我们把周围的文档根目录引号。 If the path does not have any spaces in it, do not quote the path.如果路径不包含任何空格,不要引用路径。 If the directory used for your sites were, for example MySites instead of My Sites, the document root line would look like this instead:如果您的网站使用的目录中一样,我的地盘,而不是如MySites,文件根线,而不是看起来像这样:
DocumentRoot C:\MySites\Site1 DocumentRoot的ç:\ MySites \站点1
Resolving the DNS issue解决DNS问题
Obviously, if you typed http://site1.local in your browser, it would not be found by your Internet provider's DNS server.显然,如果你输入你的浏览器http://site1.local,也不会找到你的互联网服务提供商的 DNS服务器。 We're next going to edit another file to work around that.我们下一步将要编辑另一个文件,以解决这一问题。 The second file you need to edit is called hosts, with no file extension.第二个文件,你需要编辑的称为主机, 没有文件扩展名。 It is a Windows system file and it will enable you to enter specific addresses for specific domains instead of using a DNS lookup.这是Windows系统文件,它将使你能够进入,而不是使用DNS查找特定领域的具体地址。 The normal location for this file is:此文件的正常位置是:
C:\WINNT\system32\drivers\etc\hosts
or或
C:\Windows\system32\drivers\etc\hosts
If you don't find it there, do a search in your windows directory for the word hosts in the file name.如果你没有找到它,不要在文件名中的字承载在Windows目录中搜索。 The file you want is called hosts, with no file extension.你想要的是该文件称为主机,没有文件扩展名。 The correct file will begin with the following lines:正确的文件将开始与以下几行:
# Copyright (c) 1993-1999 Microsoft Corp. #版权所有(c)1993-1999微软 # # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. #这是一个HOSTS文件由Microsoft TCP / IP的Windows使用的样本。
Once again, in this file, the octothorpe character is a comment marker.再次,在这个文件中,井号字符是注释标记。 Lines beginning with it are comments.线,它开始是注释。 In all likelihood, there will be nothing there, except for comments.在所有的可能性,会有什么都没有,除了征求意见。 If there are any other non-commented entries, leave them alone.如果有任何其他非注释的条目,让他们孤独。 Just go to the bottom of the file, below all the comments and any existing entries and add the following two lines:只要到该文件底部,下面所有的意见和任何现有的条目,并添加下面两行:
127.0.0.1 site1.local 127.0.0.1 site1.local 127.0.0.1 site2.local 127.0.0.1 site2.local
That's all you need to do there.这就是你需要做什么。 Save and close the hosts file.保存并关闭该主机文件。
You're almost done!您快完成了! The only remaining thing you need to do is to re-start the Apache server.剩下的唯一的事情,你需要做的是重新启动Apache服务器。 You need to do this because Apache only reads the configuration file when it first starts up.你需要这样做,因为Apache只能读取配置文件时,第一次启动。 Click Start->Programs->Apache HTTP Server->Control Apache Server->Restart.单击开始->“程序-> Apache的HTTP服务器>”控制Apache服务器->“重新启动。 If you don't have that menu item, open a command prompt and change to the Apache directory, and type the following command and press the Enter key:如果你没有这样的菜单项,打开一个命令提示符并切换到Apache的目录,然后键入以下命令,然后按下回车键:
apache -w -n "Apache" -k restart
You should see a message like this:你应该看到这样的信息:
The Apache service is restarting.
The Apache service has restarted.
That's it!就是这样! You're done!大功告成! Close the command window and start your web browser.关闭命令窗口,并启动Web浏览器。 In the browser's address bar, type http://site1.local and hit the Enter key.在浏览器的地址栏中,键入http://site1.local,然后按下回车键。 You should now see your local copy of your site1.您现在应该可以看到你对你的站点1的本地副本。
Okay, now I'll mention one very small, but possibly important, caveat.好吧,现在我将提到一个非常小的,但也可能很重要,告诫。 When you create the virtual hosts like this, the default http://localhost will no longer work.当您建立这样的虚拟主机,默认http://localhost的将不再起作用。 In many cases, that is unimportant.在许多情况下,这是不重要的。 However, if you're using something like phpMyAdmin, you'll still need it.不过,如果你使用像phpMyAdmin的东西,你还是会需要它。 The solution to that is to create one additional virtual host called "localhost" that points to the original Apache htdocs folder.该解决方案是创建一个额外的虚拟主机所谓的“localhost”,为原来的Apache的htdocs文件夹点。 It might look something like this:它看起来像这样:
<VirtualHost 127.0.0.1> <VirtualHost 127.0.0.1> DocumentRoot C:\Apache\htdocs DocumentRoot的ç:\的Apache \ htdocs中 ServerName localhost服务器名本地主机 </VirtualHost> </虚拟主机>
Don't forget to include that additional virtual host when you edit the Windows hosts file.不要忘记,包括额外的虚拟主机,当您编辑Windows主机文件。
Note that there are other optional settings you can use to configure the virtual host.请注意,还有其他可选的设置,你可以用它来配置虚拟主机。 The above uses only two lines and that's all that's really necessary.以上仅使用两行,这一切,实在是很必要的。 You can read about other options in the Apache documentation .你可以读到其他选项Apache文档 。 Note that this link is to the Apache web site and it will
原文转载:apptools.com
发表评论
-
php 乱码问题 未解决
2011-02-11 15:08 1295如果你在网上搜索 “a ... -
zend studio7 调试 图解
2011-02-09 14:08 2518作为PHP的集成开发环境,以Eclipse为宿主的zend s ... -
转载PHP isset()&&&&&unset()
2011-01-26 16:03 1153原文:http://teddywang.iteye ... -
转载 I18N,L10N的缩写及延伸知识
2011-01-24 15:58 1012I18N 是 internationalization 的缩写 ... -
empty,is_null,isset的区别
2011-01-24 13:58 1145http://happmaoo.iteye.com/blog/ ... -
php中isset和empty区别
2011-01-24 11:30 963http://seawomen.iteye.com/blog/ ... -
PHP $_POST
2011-01-24 11:09 785http://taobeibei.iteye.com/bl ... -
PHP $_GET
2011-01-24 11:08 770http://taobeibei.iteye.com/blog ... -
PHP 表单和用户输入
2011-01-24 11:06 801http://taobeibei.iteye.com/blog ... -
基本的 PHP 语法
2011-01-24 11:05 735http://taobeibei.iteye.com/blog ... -
转载 PHP 数组(2)
2011-01-24 10:57 719原文:http://taobeibei.iteye.com ... -
转载 PHP 数组(1)
2011-01-24 10:55 1126原文:http://batwyx.iteye.com/blog ... -
zend studio 快捷键
2011-01-21 13:30 1236编辑功能快捷键 Ctrl + / 单行注释 Ctrl ...
相关推荐
3. **虚拟主机** 技术极大地提升了服务器资源的利用率,允许企业在一个硬件平台上运行多个项目,降低了成本。 对于网站管理者、开发者以及网络管理员而言,掌握这些配置是必备技能之一。尤其对于那些需要同时维护多...
此文档适用于lamp环境apache虚拟主机的搭建,使用lamp环境搭建虚拟主机的新手,可以参看此文档。
- `<VirtualHost 192.168.16.250:8080>`:定义另一个虚拟主机容器,其中`192.168.16.250:8080`表示该虚拟主机绑定到同一IP地址的不同端口。 - 其余配置项与基于名称的虚拟主机相同。 **3.3 特点与应用场景** - 同...
要实现虚拟主机,我们需要在 `/etc/apache2/sites-available/` 目录下创建一个新的配置文件。例如,我们可以创建一个名为 `stone` 的文件,内容如下: ``` *:80> ServerName stone.com ServerAlias *.wanglei.com...
通过虚拟主机技术,可以在同一台物理服务器上运行多个不同的网站,这对于节省资源和提高效率非常有用。在Apache中,虚拟主机可以通过基于名称、基于IP或基于端口的方式进行配置。 #### 二、核心模块加载 在Apache...
在一台物理服务器上,可以设置多个独立的虚拟主机,每个虚拟主机对外表现为一个单独的网站,它们通过不同的域名来区分。Apache通过Host模块来实现这一功能。 1. **安装Apache** 在Windows系统中,你可以从Apache...
在Linux环境下配置Apache虚拟主机是一项关键的服务器管理技能,它允许在同一台物理服务器上运行多个独立的网站,每个网站都拥有自己的域名、文档根目录、错误日志等配置。以下是对给定文件信息中提到的知识点进行的...
在Apache中配置虚拟主机允许你在一个物理服务器上运行多个网站,从而提高了资源利用率并降低了运维成本。下面我们将详细介绍如何配置Apache虚拟主机。 1. **虚拟主机类型** Apache支持两种类型的虚拟主机:基于...
具体的Apache虚拟主机配置,详细描述Apache虚拟主机的配置过程及原理
资源名称:Apache服务器虚拟主机虚拟目录配置 资源截图: 资源太大,传百度网盘了,链接在附件中,有需要的同学自取。
Apache搭建虚拟主机(在本机起个假域名来访问php网站),可搭建许多个虚拟主机,假域名.zip
Apache 虚拟主机配置是Web服务器管理中的一个重要环节,允许在一个单一的Apache实例上运行多个独立的网站。Apache虚拟主机允许通过IP地址、端口或域名来区分不同的站点,从而提高了服务器资源的有效利用和管理效率。...
详细讲解apache安装 php和apache整合 虚拟目录 虚拟主机
然后,为每个虚拟主机创建一个`<VirtualHost>`块。在这个块内,我们可以指定ServerName(对应于网站的域名)、DocumentRoot(网站内容的根目录)和其他配置选项。例如,为两个不同的网站example1.com和example2.com...
例如,一个虚拟主机可以监听80端口,另一个可以监听8080端口。配置时,需要在`<VirtualHost>`指令中指定监听的端口,如`Listen 8080`,然后设置`DocumentRoot`来指定该虚拟主机的根目录。 2. **基于IP的虚拟主机**...
Apache虚拟主机配置文件 httpd-vhosts.comf
在Apache的配置文件中,你可以创建一个新的虚拟主机配置段。例如: ```apache *:80> ServerName example.com DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example....