• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

linux环境apache多端口配置虚拟主机的方法深入介绍_php技巧

php 搞代码 3年前 (2022-01-26) 33次浏览 已收录 0个评论

默认情况下,linux上apache使用的
默认文档目录是:/var/www
默认端口是:80
如果想发布自己的一个系统资源目录,可以使用下面的方法,执行如下命令:
(1)添加监听端口
#cd /etc/apache2
#vim ports.conf
文件添加:
NameVirtualHost *:8000
Listen 8000
(2)配置虚拟目录
#cd /etc/apache2/sites-available
#cp default default-me
#vim default-me
文件内容如下:

<VirtualHost *:<STRONG>8000</STRONG> ><BR>    ServerAdmin webmaster@localhost<BR>    DocumentRoot /<STRONG>wwwroot</STRONG><BR>    <BR>Options FollowSymLinks<BR>AllowOverride None<BR>    <BR>    <Directory /<STRONG>wwwroot</STRONG>/ ><BR>Options Indexes FollowSymLinks MultiViews<BR>AllowOverride None<BR>Order allow,deny<BR>allow from all<BR>    <BR>    ErrorLog /var/log/apache2/error.log<BR>    # Possible values include: debug, info, notice, warn, error, crit,<BR>    # alert, emerg.<BR>    LogLevel warn<BR>    CustomLog /var/log/apache2/access.log combined<BR><BR>


粗体部分是关键点。
(3)发布站点
# ln -s /etc/apache2/sites-available/default-me /etc/apache2/sites-enabled/001-default
(4)重启服务
#/etc/init.d/apache2 restart
(5)测试
http://localhost:8000/
如果能够正常访问就说明配置正确了。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR># Virtual Hosts<BR>#<BR># If you want to maintain multiple domains/hostnames on your<BR># machine you can setup VirtualHost containers for them. Most configurations<BR># use only name-based virtual hosts so the server doesn't need to worry about<BR># IP addresses. This is indicat<i style="color:transparent">本¥文来源gaodai$ma#com搞$代*码*网(</i><strong>搞代gaodaima码</strong>ed by the asterisks in the directives below.<BR>#<BR># Please see the documentation at<BR># <BR># for further details before you try to setup virtual hosts.<BR>#<BR># You may use the command line option '-S' to verify your virtual host<BR># configuration.<BR>#<BR># Use name-based virtual hosting.<BR>#<BR>NameVirtualHost *:81<BR>NameVirtualHost *:82<BR>NameVirtualHost *:83<BR>NameVirtualHost *:84<BR>NameVirtualHost *:85<BR>NameVirtualHost *:86<BR>#<BR># VirtualHost example:<BR># Almost any Apache directive may go into a VirtualHost container.<BR># The first VirtualHost section is used for all requests that do not<BR># match a ServerName or ServerAlias in any  block.<BR>#<BR><BR>ServerAdmin [email protected]<BR>DocumentRoot D:/AppServ/www/www-nongye<BR>ServerName www.dede.com<BR>ErrorLog D:/AppServ/www/www-nongye/errornongye.log<BR>CustomLog logs/dummy-host2.appservnetwork.com-access_log common<BR><BR><BR><BR>Options FollowSymLinks<BR>#Deny from all<BR>Allow from all<BR><BR>ServerAdmin [email protected]<BR>DocumentRoot D:/AppServ/www-chinaec<BR>ServerName www.dede.com<BR>DirectoryIndex index.php index.html<BR>ErrorLog D:/AppServ/www-chinaec/errornongjiale.log<BR>CustomLog logs/dummy-host2.appservnetwork.com-access_log common<BR><BR><BR>ServerAdmin [email protected]<BR>DocumentRoot D:/AppServ/www/www-05110<BR>ServerName www.dede.com<BR>ErrorLog D:/AppServ/www/www-05110/errornong05110.log<BR>CustomLog logs/dummy-host2.appservnetwork.com-access_log common<BR><BR><BR>ServerAdmin [email protected]<BR>DocumentRoot D:/AppServ/www/wordpress<BR>ServerName www.dede.com<BR>ErrorLog D:/AppServ/www/wordpress/errornongwordpress.log<BR>CustomLog logs/dummy-host2.appservnetwork.com-access_log common<BR><BR><BR>ServerAdmin [email protected]<BR>DocumentRoot D:/AppServ/www/magento<BR>ServerName www.dede.com<BR>ErrorLog D:/AppServ/www/magento/errormagento.log<BR>CustomLog logs/dummy-host2.appservnetwork.com-access_log common<BR><BR><BR>ServerAdmin [email protected]<BR>DocumentRoot D:/AppServ/www/magento1322<BR>ServerName www.dede.com<BR>ErrorLog D:/AppServ/www/magento1322/errormagento1322.log<BR>CustomLog logs/dummy-host2.appservnetwork.com-access_log common<BR><BR><BR>ServerAdmin [email protected]<BR>DocumentRoot D:/AppServ/www/www-nongjiale<BR>ServerName www.dede.com<BR>ErrorLog D:/AppServ/www/www-nongjiale/errornongjiale.log<BR>CustomLog logs/dummy-host2.appservnetwork.com-access_log common<BR><BR><BR>ServerAdmin [email protected]<BR>DocumentRoot "C:/Apache2.2/docs/dummy-host2.x"<BR>ServerName dummy-host2.x<BR>ErrorLog "logs/dummy-host2.x-error.log"<BR>CustomLog "logs/dummy-host2.x-access.log" common<BR> <BR>


1、单域名单端口设置
如:www.abc.com 默认用80访问

特别说明,apache的配置默认都在安装目录下的conf目录里面
或者是/etc/apache2
不过一定要注意,listen.conf文件中端口监听是否开启
如下图,表示已经开启80端口监听

直接默认
1、单域名单端口设置
如:www.abc.com 默认用80访问

特别说明,apache的配置默认都在安装目录下的conf目录里面
或者是/etc/apache2
不过一定要注意,listen.conf文件中端口监听是否开启
如下图,表示已经开启80端口监听
直接默认修改default-server.conf

这个配置最好简单
安装好了,之后,默认已经能够使用了,只是要把它修改成你需要的域名及访问路径罢了。

给一个标准配置吧

DocumentRoot "/srv/www/htdocs"<BR>#<BR># Configure the DocumentRoot<BR>#<BR><BR># Possible values for the Options directive are "None", "All",<BR># or any combination of:<BR>#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews<BR>#<BR># Note that "MultiViews" must be named *explicitly* --- "Options All"<BR># doesn't give it to you.<BR>#<BR># The Options directive is both complicated and important.  Please see<BR># http://httpd.apache.org/docs-2.2/mod/core.html#options<BR># for more information.<BR>Options None<BR># AllowOverride controls what directives may be placed in .htaccess files.<BR># It can be "All", "None", or any combination of the keywords:<BR>#   Options FileInfo AuthConfig Limit<BR>AllowOverride None<BR># Controls who can get stuff from this server.<BR>Order allow,deny<BR>Allow from all<BR><BR>


2、单域名多端口设置

<BR>    Options None<BR>    AllowOverride None<BR>    Order allow,deny<BR>    Allow from all<BR><BR><BR>    Options None<BR>    AllowOverride None<BR>    Order allow,deny<BR>    Allow from all<BR><BR>NameVirtualHost   *:80<BR>NameVirtualHost   *:81<BR><BR>  DirectoryIndex  index.html index.php<BR>  ServerName   "www.abc.com "<BR>  DocumentRoot   "/srv/www/htdocs/"  <BR>  <BR><BR>  DirectoryIndex   index.php<BR>    ServerName   "www.abc.com:81 "<BR>  DocumentRoot   "/srv/www/htdocs/bbs/"  <BR>  <BR>


3、多域名多端口设置

<BR>    Options None<BR>    AllowOverride None<BR>    Order allow,deny<BR>    Allow from all<BR><BR><BR>    Options None<BR>    AllowOverride None<BR>    Order allow,deny<BR>    Allow from all<BR><BR><BR>    Options None<BR>    AllowOverride None<BR>    Order allow,deny<BR>    Allow from all<BR><BR>NameVirtualHost   *:80<BR>NameVirtualHost   *:81<BR><BR>  DirectoryIndex  index.html index.php<BR>  ServerName   "www.abc.com "<BR>  DocumentRoot   "/srv/www/htdocs/"  <BR>  <BR><BR>  DirectoryIndex  index.html index.php<BR>  ServerName   "www.btc.com "<BR>  DocumentRoot   "/srv/www/htdocs/btc"  <BR>  <BR><BR>  DirectoryIndex   index.php<BR>    ServerName   "www.abc.com:81 "<BR>  DocumentRoot   "/srv/www/htdocs/bbs/"  <BR>  <BR>


需要注意的问题是,多端口监听,一定要注意listen.conf文件,是否开启了相应端口。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:linux环境apache多端口配置虚拟主机的方法深入介绍_php技巧

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址