配备PHP虚拟目录

WBOY
Freigeben: 2016-06-13 10:39:09
Original
1055 Leute haben es durchsucht

配置PHP虚拟目录

----------
摘要
----------
本文极为简要的介绍了如何在Windows平台下安装Apache2.2.x并配置虚拟目录. 以作为快速安装的参考. 详细的设置最好的文档是官方的说明文档见下方的链接, 在安装配置的时候仔细的查阅文档是很好的解决办法.
1. Apache HTTP Server Version 2.2 英文文档
2. Apache HTTP Server Version 2.2 中文文档


----------
准备条件
----------
http://httpd.apache.org/ 下载相应版本的Apache. (注意: 2.0与2.2版本的Apache对应的Module版本页不同, 互相不兼容, 因此需要根据应用程序来下载相应版本的Apache). 如果不需要使用ssl, 则要下载 Apache 2.x.x-win32-x86-no_ssl.msi, 如果需要使用, 则需要下载Apache 2.x.x-win32-x86-openssl-x.x.x.msi

----------
安装
----------
双击安装程序, 它将引导你完成整个安装过程。请确保你输入正确的服务器URL(如果你的服务器没有DNS名称,你可以直接输入IP地址)。建议将Apache安装成" for all Users,on Port 80,as a service" Apache将自动安装一个系统服务以自动启动。注意:如果你已经有一个IIS或者其它的程序使用80端口,安装可能会失败。如果是这样,你可以到程序目录下的Apache Group\Apache2\conf目录中找到文件httpd.conf,将其中的Listen 80改成一个不用的端口,比如Listen 81。然后重新运行这个安装程序,这次应该不会再有问题了。

安装结束之后在
浏览器中键入 http://loccalhost,如果呈现了一个已经配置好的网站,那么Apache就安装成功了。 如果你将Apache安装成一个服务,它将以本地system帐户来运行。为Apache创建一个单独的用户来运行它将会更安全一些。

打开Apache的安装目录, 找到文件 /conf/httpd.conf, 打开它进行配置的编辑. 配置文件中对于各项都有比较详细的描述, 在配置结束之后可以运行开始菜单中Apache安装文件夹中的Test Configuration工具来检验配置文件是否正确. 如果配置不正确会给出简要的说明. 如果在配置结束之后通过了Test Configuration工具, 但是仍然不能够顺利运行Apache, 可以到[Apache安装目录]/logs/ 这个目录中查看记录, 以找出问题所在.

----------
配置 httpd.conf文件
----------
# 设置文档主目录, 后面的就是磁盘的目录
DocumentRoot "D:/Programs/Apache2.2/htdocs"

# 添加虚拟目录, 下面的设置在浏览器中输入 http://localhost/webpath/ 的时候机会访问服务器的"D:/Programs/WebPath"目录
Alias /webpath/ "D:/Programs/WebPath"
# 当/webPath 后面不加"/"的话, 在浏览器中可以输入 http://localhost/webpath Apache会自动的在后面添加"/"
Alias /webpath "D:/Programs/WebPath"

# URL 重定向
Redirect permanent /foo/ http://www.example.com/bar/

# 设定虚拟主机: 请参考 http://lamp.linux.gov.cn/Apache/ApacheMenu/vhosts/index.html

?

  在WIN下安装APACHE配置虚拟目录和UNIN下基本是一样的
  就是修改httpd.conf
  1:单个IP对应单个玉米
  例如:www.phpunion.com对应192.168.1.1
  www.feelone.net对应192.168.1.2
  在httpd.conf中加入如下指令
   #对应玉米所指向的IP
   DocumentRoot "c:/web/php" #www.phpunion.com要指向的目录,注意一定要有""
   ServerName www.phpunion.com #所要绑的玉米
  

?


   #对应玉米所指向的IP
   DocumentRoot "c:/web/feel" #www.feelone.net要指向的目录,注意一定要有""
   ServerName www.feelone.net #所要绑的玉米
  

  剩下的可以继续绑!

?


  2:单个IP对应多个玉米

?

NameVirtualHost 192.168.1.1 #记得一定要有着句啊!
   #对应玉米所指向的IP
    DocumentRoot "c:/web/php" #www.phpunion.com要指向的目录,注意一定要有""
   ServerName www.phpunion.com #所要绑的玉米
  


#对应玉米所指向的IP
  DocumentRoot "c:/web/feel" #www.feelone.net要指向的目录,注意一定要有""
   ServerName www.feelone.net #所要绑的玉米
  



  这样就绑上对应的目录了,如果没有NameVirtualHost 192.168.1.1 这个指令的话,所有的玉米就都指到php目录了.
  然后重新启动apache,就可以看到所指的玉米对应相应的虚拟目录!

?


Example:

ServerAdmin [email protected]
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log

?

?

?

?

?

今天网站建设技术部的PHP程序员教了我一个在本地实现虚拟一个域名来访问本机电脑的数据的方法,首先说说我本地的环境是:WIN2003+xampp。其实能实现效果就行,直接用xampp的最好方法就是省事,不用一个一个软件安装!然后下面一步一步实现虚拟一个www.123.com来访问本地网站程序。
1.关闭xampp的apache,然后找到C:\xampp\apache\conf\extra\httpd-vhosts.conf文件:
在##NameVirtualHost *:80 下面加入以下代码,其中的IP为本地电脑的IP,可以进入CMD使用ipconfig查询到本机IP
NameVirtualHost 192.168.1.101:80
然后把以下代码复制一份
##
##ServerAdmin [email protected]
##DocumentRoot "C:/xampp/htdocs/dummy-host2.localhost"
##ServerName dummy-host2.localhost
##ServerAlias www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
##

修改成以下代码

##ServerAdmin [email protected]
DocumentRoot "E:/php/ecshop2.72"
ServerName www.123.com
ServerAlias www.123.com
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined

其中DocumentRoot 是本机网站制作程序的路径,ServerName及ServerAlias 就是要虚拟的域名网址,这个随便你高兴了
2.找到C:\xampp\apache\conf\httpd.conf文件,找到以下代码:
DocumentRoot "C:/xampp/htdocs"

把上面的两个网站目录的路径修改成上面设置的路径
DocumentRoot "E:/php"

因为设置了虚拟的域名网址,所以路径不用再加上网站的文件夹名称了
3.然后打开C:\WINDOWS\system32\drivers\etc\hosts 文件,
在127.0.0.1 localhost下添加你要添加的虚拟域名网址
127.0.0.1 localhost
192.168.1.101 www.123.com
呵呵,修改这三个文件之后就OK了,现在可以重新启动xampp的apache了,然后在IE里输入www.123.com就能访问本地的网站程序了,这样测试的好处是能把本机虚拟成服务器,有些东东很方便就能调试!当然,用localhost也是还可以访问了,这个功能用不到的话也没必要这么搞,我是因为有时用到Magento程序,使用域名会更好,不会有一些莫名其妙的问题。当然了,如果你有好几个网站的话,每次都要修改一下C:\xampp \apache\conf\extra\httpd-vhosts.conf对应的DocumentRoot "E:/php/ecshop2.72",因为我的网页设计的PHP程序都是放在E盘下的PHP文件夹,然后每个网站就一个文件夹,这样每次只需要修改一个文件就OK了,看个人爱好了,共享出来让大家玩玩,嘿嘿!

?


?

详细配置:http://httpd.apache.org/docs/2.2/vhosts/

中文配置:http://www.zzxj.net/web/manual/ApacheMenu/rewrite/rewrite_guide.html

?

?

?

?

Apache虚拟主机的配置

?

虚拟主机的配置

?

基于IP地址的虚拟主机配置
Listen 80
DocumentRoot /www/example1
ServerName www.example1.com
DocumentRoot /www/example2
ServerName www.example2.org

?

?

?

基于IP和多端口的虚拟主机配置
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

?

DocumentRoot /www/example1-80
ServerName www.example1.com
DocumentRoot /www/example1-8080
ServerName www.example1.com
DocumentRoot /www/example2-80
ServerName www.example1.org
DocumentRoot /www/example2-8080
ServerName www.example2.org

?

单个IP地址的服务器上基于域名的虚拟主机配置
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here

?

在多个IP地址的服务器上配置基于域名的虚拟主机
Listen 80
# This is the “main” server running on 172.20.30.40
ServerName server.domain.com
DocumentRoot /www/mainserver
# This is the other address
NameVirtualHost 172.20.30.50
DocumentRoot /www/example1
ServerName www.example1.com
# Other directives here …
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here …

?

在不同的端口上运行不同的站点
基于多端口的服务器上配置基于域名的虚拟主机。
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
ServerName www.example1.com
DocumentRoot /www/domain-80
ServerName www.example1.com
DocumentRoot /www/domain-8080
ServerName www.example2.org
DocumentRoot /www/otherdomain-80
ServerName www.example2.org
DocumentRoot /www/otherdomain-8080

?

基于域名和基于IP的混合虚拟主机的配置:
Listen 80
NameVirtualHost 172.20.30.40
DocumentRoot /www/example1
ServerName www.example1.com
DocumentRoot /www/example2
ServerName www.example2.org
DocumentRoot /www/example3
ServerName www.example3.net

?

?

?

自己的设置

?

hosts

?

?

?

127.0.0.1 localhost
127.0.0.1 fantsi

?

?

?

httpd.conf

?

?

?

Alias /fantsi/ "E:/xampp/htdocs/fantsi"

NameVirtualHost 127.0.0.1

DocumentRoot "E:/xampp/htdocs"
ServerName localhost
ServerAlias localhost



DocumentRoot "E:/xampp/htdocs/fantsi"
ServerName fantsi
ServerAlias fantsi

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!