linux环境apache多端口配置虚拟主机的方法深入介绍
<p>默认情况下,linux上apache使用的<br>
默认文档目录是:/var/www<br>
默认端口是:80<br>
如果想发布自己的一个系统资源目录,可以使用下面的方法,执行如下命令:<br><strong><font>(1)添加监听端口</font></strong><br>
#cd /etc/apache2<br>
#vim ports.conf<br>
文件添加:<br><strong>NameVirtualHost *:8000<br>
Listen 8000</strong><br><font><strong>(2)配置虚拟目录</strong></font><br>
#cd /etc/apache2/sites-available<br>
#cp default default-me<br>
#vim default-me<br><strong>文件内容如下:</strong></p>
<p class="codetitle">
<span><u>复制代码</u></span> 代码如下:</p>
<p class="codebody">
<br>
<VirtualHost *:<strong>8000</strong> ><br>
ServerAdmin webmaster@localhost<br>
DocumentRoot /<strong>wwwroot</strong><br>
<Directory / ><br>
Options FollowSymLinks<br>
AllowOverride None<br>
</Directory><br>
<Directory /<strong>wwwroot</strong>/ ><br>
Options Indexes FollowSymLinks MultiViews<br>
AllowOverride None<br>
Order allow,deny<br>
allow from all<br>
</Directory><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>
</VirtualHost></p>
<p>
<br><strong>粗体部分是关键点。<br><font>(3)发布站点</font></strong><br>
# ln -s /etc/apache2/sites-available/default-me /etc/apache2/sites-enabled/001-default<br><strong><font>(4)重启服务</font></strong><br>
#/etc/init.d/apache2 restart<br><strong><font>(5)测试</font></strong><br>
http://localhost:8000/<br>
如果能够正常访问就说明配置正确了。</p>
<p class="codetitle">
<span><u>复制代码</u></span> 代码如下:</p>
<p class="codebody">
<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<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 indicated by the asterisks in the directives below.<br>
#<br>
# Please see the documentation at<br>
# <URL:http://httpd.apache.org/docs/2.2/vhosts/ ><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 <VirtualHost> block.<br>
#<br>
<VirtualHost *:81><br>
ServerAdmin jsw7001@hotmail.com<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>
</VirtualHost><br>
<VirtualHost *:82><br>
<Directory "D:/AppServ/www-chinaec" ><br>
Options FollowSymLinks<br>
#Deny from all<br>
Allow from all<br>
</Directory><br>
ServerAdmin jsw7001@hotmail.com<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>
</VirtualHost><br>
<VirtualHost *:83><br>
ServerAdmin jsw7001@hotmail.com<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>
</VirtualHost><br>
<VirtualHost *:84><br>
ServerAdmin jsw7001@hotmail.com<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>
</VirtualHost><br>
<VirtualHost *:85><br>
ServerAdmin jsw7001@hotmail.com<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>
</VirtualHost><br>
<VirtualHost *:86><br>
ServerAdmin jsw7001@hotmail.com<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>
</VirtualHost><br>
<VirtualHost *:88><br>
ServerAdmin jsw7001@hotmail.com<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>
</VirtualHost><br>
<VirtualHost *:80><br>
ServerAdmin webmaster@dummy-host2.x<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>
</VirtualHost></p>
<p>
<br><strong>1、单域名单端口设置</strong><br>
如:www.abc.com 默认用80访问<br><br>
特别说明,apache的配置默认都在安装目录下的conf目录里面<br>
或者是/etc/apache2<br>
不过一定要注意,listen.conf文件中端口监听是否开启<br>
如下图,表示已经开启80端口监听<br><br><strong>直接默认<br>
1、单域名单端口设置</strong><br>
如:www.abc.com 默认用80访问<br><br>
特别说明,apache的配置默认都在安装目录下的conf目录里面<br>
或者是/etc/apache2<br>
不过一定要注意,listen.conf文件中端口监听是否开启<br>
如下图,表示已经开启80端口监听<br>
直接默认修改default-server.conf<br><br><strong>这个配置最好简单</strong><br>
安装好了,之后,默认已经能够使用了,只是要把它修改成你需要的域名及访问路径罢了。<br><br>
给一个标准配置吧</p>
<p class="codetitle">
<span><u>复制代码</u></span> 代码如下:</p>
<p class="codebody">
<br>
DocumentRoot "/srv/www/htdocs"<br>
#<br>
# Configure the DocumentRoot<br>
#<br>
<Directory "/srv/www/htdocs"><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>
</Directory></p>
<p>
<br><strong>2、单域名多端口设置</strong></p>
<p class="codetitle">
<span><u>复制代码</u></span> 代码如下:</p>
<p class="codebody">
<br>
<Directory "/srv/www/htdocs/bbs"><br>
Options None<br>
AllowOverride None<br>
Order allow,deny<br>
Allow from all<br>
</Directory><br>
<Directory "/srv/www/htdocs/"><br>
Options None<br>
AllowOverride None<br>
Order allow,deny<br>
Allow from all<br>
</Directory><br>
NameVirtualHost *:80<br>
NameVirtualHost *:81<br>
<VirtualHost *:80><br>
DirectoryIndex index.html index.php<br>
ServerName "www.abc.com "<br>
DocumentRoot "/srv/www/htdocs/" <br>
</VirtualHost><br>
<VirtualHost *:81><br>
DirectoryIndex index.php<br>
ServerName "www.abc.com:81 "<br>
DocumentRoot "/srv/www/htdocs/bbs/" <br>
</VirtualHost></p>
<p>
<br><strong>3、多域名多端口设置</strong></p>
<p class="codetitle">
<span><u>复制代码</u></span> 代码如下:</p>
<p class="codebody">
<br>
<Directory "/srv/www/htdocs/btc"><br>
Options None<br>
AllowOverride None<br>
Order allow,deny<br>
Allow from all<br>
</Directory><br>
<Directory "/srv/www/htdocs/bbs"><br>
Options None<br>
AllowOverride None<br>
Order allow,deny<br>
Allow from all<br>
</Directory><br>
<Directory "/srv/www/htdocs/"><br>
Options None<br>
AllowOverride None<br>
Order allow,deny<br>
Allow from all<br>
</Directory><br>
NameVirtualHost *:80<br>
NameVirtualHost *:81<br>
<VirtualHost *:80><br>
DirectoryIndex index.html index.php<br>
ServerName "www.abc.com "<br>
DocumentRoot "/srv/www/htdocs/" <br>
</VirtualHost><br>
<VirtualHost *:80><br>
DirectoryIndex index.html index.php<br>
ServerName "www.btc.com "<br>
DocumentRoot "/srv/www/htdocs/btc" <br>
</VirtualHost><br>
<VirtualHost *:81><br>
DirectoryIndex index.php<br>
ServerName "www.abc.com:81 "<br>
DocumentRoot "/srv/www/htdocs/bbs/" <br>
</VirtualHost></p>
<p>
<br>
需要注意的问题是,多端口监听,一定要注意listen.conf文件,是否开启了相应端口。</p>
頁:
[1]