国产探花免费观看_亚洲丰满少妇自慰呻吟_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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 田东县| 东方市| 当涂县| 贡山| 东安县| 开封县| 宜兴市| 长子县| 南康市| 孟村| 郓城县| 元江| 大荔县| 墨江| 类乌齐县| 黄龙县| 巧家县| 财经| 万山特区| 安福县| 济阳县| 淮北市| 皮山县| 兴业县| 黑山县| 乌鲁木齐市| 体育| 蚌埠市| 汉寿县| 合山市| 华阴市| 怀柔区| 五台县| 宁德市| 乐山市| 东乌珠穆沁旗| 枝江市| 安康市| 青冈县| 凤庆县| 潞西市|