日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Apache搭建多个站点方法详解

發布時間:2025/5/22 编程问答 77 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apache搭建多个站点方法详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
www.111cn.net 編輯:Bolshevik 來源:轉載 Apache的虛擬主機是一種允許在同一臺機器上配置多個不同站點的web服務器環境的,就是iis一樣可以創建多站點了,但是apache需要在編輯狀態操作,不能像windows iis直接點擊幾下就好了,下面我來給各位介紹配置方法。

最平常的大概有3種方法。

第一種:單IP不同端口

第二種:多IP同端口(獨立IP的虛擬空間)

第三種:域名綁定根目錄的方式(共享IP的虛擬空間)


Apache的核心配置文件名是”httpd.conf”,其所存放的路徑在Apache目錄下的conf文件夾下。修改它只需要使用記事本(建議使用其他編輯器,帶行數的那種,方便修改),生效的話只需要保存httpd.conf,重啟apache即可。

下面多站點支持的話,修改httpd.conf的第187~264行(不同的httpd.conf可能有差異),也就是在ServerAdmin和ServerName那里,大部分是注釋。下面是主要修改的地方。

注意:如果是服務器請備份httpd.conf后再修改文件。

?代碼如下復制代碼

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any?requests that aren't handled by a
# <VirtualHost> definition.? These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.? This address appears on some server-generated pages, such
# as error documents.? e.g. admin@your-domain.com
#
ServerAdmin admin@example.com

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other?
# <Directory> blocks below.
#
<Directory />
??? AllowOverride All
??? Require all denied
</Directory>

#
# 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.
#

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "g:/www"
<Directory "g:/www">
??? #
??? # 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:
??? #?? Options FileInfo AuthConfig Limit
??? #
??? AllowOverride All

??? #
??? # Controls who can get stuff from this server.
??? #
??? Require all granted
</Directory>

第一種一般是測試環境,畢竟加了端口,如何綁定域名,訪問的時候域名后面也需加端口。

例子分別通過80和8080訪問不同的根目錄。

大概在50幾行有個Listen 80,在下面添加8080端口。

?代碼如下復制代碼

Listen 80
Listen 8080<VirtualHost *:80>?
??? ServerAdmin admin@myxzy.com?
??? ServerName localhost:80?
??? DocumentRoot "g:/www1"?
???? <Directory "g:/www1">?
???? Options? Indexes FollowSymLinks?
???? AllowOverride All?
???? Require all granted?
?? </Directory>???
</VirtualHost>?
<VirtualHost *:8080>?
??? ServerAdmin admin@myxzy.com
??? ServerName localhost:8080??
??? DocumentRoot "g:/www2"?
?? <Directory "g:/www2">?
???? Options Indexes FollowSymLinks?
???? AllowOverride All?
???? Require all granted?
?? </Directory>???????
</VirtualHost>

第二種多IP同端口。

IP地址1:192.168.2.2

IP地址2:192.168.1.68

端口同是80端口。

?代碼如下復制代碼

<VirtualHost 192.168.1.68:80>?
??? ServerAdmin admin@myxzy.com?
??? ServerName localhost:80?
??? DocumentRoot "g:/www1"?
???? <Directory "g:/www1">?
???? Options FollowSymLinks?
???? AllowOverride All?
???? Require all granted?
?? </Directory>???
</VirtualHost>?
<VirtualHost 192.168.2.2:80>?
??? ServerAdmin admin@myxzy.com
??? ServerName localhost:80?
??? DocumentRoot "g:/www2"?
?? <Directory "g:/www2">?
???? Options FollowSymLinks?
???? AllowOverride All?
???? Require all granted?
?? </Directory>???????
</VirtualHost>

第三種同IP不同域名和根目錄(域名的話修改本地host演示)。

?代碼如下復制代碼


<VirtualHost 192.168.2.2:80>?
??? ServerAdmin admin@myxzy.com?
??? ServerName www.111cn.net?
??? DocumentRoot "g:/www1"?
???? <Directory "g:/www1">?
???? Options FollowSymLinks?
???? AllowOverride All?
???? Require all granted?
?? </Directory>???
</VirtualHost>?
<VirtualHost 192.168.2.2:80>?
??? ServerAdmin admin@myxzy.com
??? ServerName www.111cn.net
??? DocumentRoot "g:/www2"?
?? <Directory "g:/www2">?
???? Options FollowSymLinks?
???? AllowOverride All?
???? Require all granted?
?? </Directory>???????
</VirtualHost>

總結

以上是生活随笔為你收集整理的Apache搭建多个站点方法详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。