前言
本文將詳細(xì)記錄一下如何在單臺(tái)服務(wù)器上,利用apache的virtualhost(虛擬主機(jī))來搭建多個(gè)不同的web站點(diǎn),并且每個(gè)站點(diǎn)獨(dú)立管理自己的session,下面話不多說了,來一起看看詳細(xì)的介紹吧。
開發(fā)環(huán)境
先說下我各項(xiàng)開發(fā)環(huán)境參數(shù):
修改Apache配置
apache2.2 的配置文件路徑在 /etc/httpd/conf/httpd.conf
我們用下面的命令修改apache的配置文件:
$ vim /etc/httpd/conf/httpd.conf
添加監(jiān)聽端口
找到如下的部分,
## 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
默認(rèn)的話,應(yīng)該只會(huì)監(jiān)聽80端口,這里我們?cè)诤竺婕由嫌糜诹硗庹军c(diǎn)的端口號(hào)。例如我們A站點(diǎn)是默認(rèn)的80端口,B站點(diǎn)計(jì)劃搭建在8080端口上,最終的配置文件修改成
...#Listen 12.34.56.78:80Listen 80Listen 8080
啟動(dòng)并添加VirtualHost
接著在配置文件中找到下面的章節(jié):
### 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
上面的代碼是我已經(jīng)修改好的,默認(rèn)的話,最后兩行NameVirtualHost應(yīng)該也是被注釋掉了。 因?yàn)槲覀円獑⒂锰摂M主機(jī),所以這里就把我們之前監(jiān)聽的兩個(gè)端口都設(shè)置好。
同時(shí),將之后的配置文件修改成如下的樣子,我們先來設(shè)置默認(rèn)的80端口的站點(diǎn)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>
新聞熱點(diǎn)
疑難解答
圖片精選