国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Apache > 正文

單臺服務器中利用Apache的VirtualHost如何搭建多個Web站點詳解

2024-08-27 18:24:46
字體:
來源:轉載
供稿:網友

前言

本文將詳細記錄一下如何在單臺服務器上,利用apache的virtualhost(虛擬主機)來搭建多個不同的web站點,并且每個站點獨立管理自己的session,下面話不多說了,來一起看看詳細的介紹吧。

開發環境

先說下我各項開發環境參數:

操作系統: RedHat6.7(CentOS) WEB服務器:apache2.2 php5.6.30

修改Apache配置

apache2.2 的配置文件路徑在 /etc/httpd/conf/httpd.conf

我們用下面的命令修改apache的配置文件:

$ vim /etc/httpd/conf/httpd.conf

添加監聽端口

找到如下的部分,

## Listen: Allows you to bind Apache to specific IP addresses and/or# ports, in addition to the default. See also the <VirtualHost># directive.## Change this to Listen on specific IP addresses as shown below to# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)##Listen 12.34.56.78:80Listen 80

默認的話,應該只會監聽80端口,這里我們在后面加上用于另外站點的端口號。例如我們A站點是默認的80端口,B站點計劃搭建在8080端口上,最終的配置文件修改成

...#Listen 12.34.56.78:80Listen 80Listen 8080

啟動并添加VirtualHost

接著在配置文件中找到下面的章節:

### Section 3: Virtual Hosts## VirtualHost: If you want to maintain multiple domains/hostnames on your# machine you can setup VirtualHost containers for them. Most configurations# use only name-based virtual hosts so the server doesn't need to worry about# IP addresses. This is indicated by the asterisks in the directives below.## Please see the documentation at# <URL:http://httpd.apache.org/docs/2.2/vhosts/># for further details before you try to setup virtual hosts.## You may use the command line option '-S' to verify your virtual host# configuration.## Use name-based virtual hosting.# NameVirtualHost *:80 NameVirtualHost *:8080

上面的代碼是我已經修改好的,默認的話,最后兩行NameVirtualHost應該也是被注釋掉了。 因為我們要啟用虛擬主機,所以這里就把我們之前監聽的兩個端口都設置好。

同時,將之后的配置文件修改成如下的樣子,我們先來設置默認的80端口的站點A

## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for requests without a known# server name.#<VirtualHost *:80># ServerAdmin webmaster@dummy-host.example.com DocumentRoot /var/www/webA ServerName webA# ErrorLog logs/dummy-host.example.com-error_log# CustomLog logs/dummy-host.example.com-access_log common</VirtualHost>

默認的Apache是沒有開啟VirtualHost的,所以這些代碼都是被注釋掉了的,我們這里只需要把DocumentRoot和ServerName所在的行去掉注釋并且編輯下就好了。

DocumentRoot指的的是我們A站點的網站根目錄位置

接下來再補充上8080端口的B站點信息就好了。

<VirtualHost *:8080> DocumentRoot /var/www/webB ServerName webB</VirtualHost>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富裕县| 平利县| 德化县| 大方县| 股票| 屯昌县| 黔西| 大余县| 马龙县| 景宁| 安徽省| 河源市| 五台县| 阿拉善左旗| 普陀区| 定远县| 正镶白旗| 泰州市| 拜泉县| 武宁县| 乌兰浩特市| 佛坪县| 寿宁县| 江都市| 全州县| 比如县| 安新县| 克什克腾旗| 浦北县| 象州县| 海南省| 商城县| 建始县| 正阳县| 龙江县| 会同县| 浠水县| 东方市| 会同县| 龙江县| 肃宁县|