您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“LAMP架構(gòu)中Apache服務(wù)基于端口虛擬主機(jī)配置的示例分析”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“LAMP架構(gòu)中Apache服務(wù)基于端口虛擬主機(jī)配置的示例分析”這篇文章吧。
基于端口虛擬主機(jī)配置
前面介紹了基于域名、IP的虛擬主機(jī)配置,實(shí)際生產(chǎn)環(huán)境中使用最多的還是基于域名的虛擬主機(jī),今天介紹的基于端口的虛擬主機(jī)也不常用,但用的最多的場(chǎng)景就是:公司內(nèi)網(wǎng)(如網(wǎng)站后臺(tái)頁(yè)面、其它發(fā)布類的頁(yè)面)
基于端口的虛擬配置非常簡(jiǎn)單
默認(rèn)情況http默認(rèn)監(jiān)聽(tīng)的是80端口,所以配置基于端口的虛擬主機(jī),就是增加相應(yīng)的監(jiān)聽(tīng)端口
一:配置之前備份配置文件
[root@Centos extra]# cp httpd-vhosts.conf httpd-vhosts.conf.$(date +%F)
[root@Centos extra]# ls
httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf
httpd-vhosts.conf httpd-vhosts.conf.2016-09-09
httpd-default.conf httpd-manual.conf httpd-ssl.conf proxy-html.conf
二:配置站點(diǎn)目錄(方便測(cè)試不同端口)
[root@Centos extra]# mkdir -p /data/www/blog/
[root@Centos extra]# echo "welcome to the server of blogs">>/data/www/blog/index.html
[root@Centos extra]# cat /data/www/blog/index.html
welcome to the server of blogs
三:配置虛擬主機(jī)配置文件
1、配置前還需要到主配置文件中增加目錄控制權(quán)限
[root@Centos extra]# vi ../httpd.conf
<Directory "/data/www/bbs">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
增加如下配置
<Directory "/data/www/blog">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
實(shí)際生產(chǎn)環(huán)境中還是使用規(guī)范路徑比較好,也可以將配置修改成如下
[root@Centos extra]# vi ../httpd.conf
<Directory "/data/www">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
對(duì)上一級(jí)目錄統(tǒng)一授權(quán)
2、主配置文件增加監(jiān)聽(tīng)端口
[root@Centos extra]# vi ../httpd.conf
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
............................其中一些配置部分省略
#
#Listen 12.34.56.78:80
Listen 80
Listen 8888
Listen 9999
3、配置虛擬主機(jī)配置文件
[root@Centos extra]# vi httpd-vhosts.conf
# Virtual Hosts
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost 192.168.1.20:8888>
ServerAdmin admini@abc.com
DocumentRoot "/data/www/bbs"
ServerName 192.168.1.20
ServerAlias abc.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
<VirtualHost 192.168.1.2:9999>
ServerAdmin admini@abc.com
DocumentRoot "/data/www/blog"
ServerName 192.168.1.2
ServerAlias abc.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
4、檢查配置、重啟服務(wù)
[root@Centos extra]# ../../bin/apachectl -t
Syntax OK
[root@Centos extra]# ../../bin/apachectl graceful
[root@Centos extra]# ps -ef |grep http
root 23901019:42 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
daemon 2725 2390 0 20:33 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
daemon 2726 2390 0 20:33 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
daemon 2727 2390 0 20:33 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
root 2835 1934 0 20:39 pts/1 00:00:00 grep http
[root@Centos extra]# netstat -lnt |grep 8888
tcp 0 0 :::8888 :::* LISTEN
[root@Centos extra]# netstat -lnt |grep 9999
tcp 0 0 :::9999 :::* LISTEN
四:測(cè)試配置
[root@Centos extra]# cat /data/www/bbs/index.html
welcome to bbs.abc.com
192.168.1.20:80 this server is the server of bbs stie
[root@Centos extra]# cat /data/www/blog/index.html
welcome to the server of blogs
本地瀏覽器測(cè)試
經(jīng)過(guò)測(cè)試,訪問(wèn)正常,表明配置正確
五:主機(jī)別名的應(yīng)用
修改下剛剛的虛擬主機(jī)配置
#port bash ip
<VirtualHost 192.168.1.20:8888>
ServerAdmin admini@abc.com
DocumentRoot "/data/www/bbs"
ServerName 192.168.1.20
ServerAlias abc.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
#port bash name
<VirtualHost *:9999>
ServerAdmin admini@abc.com
DocumentRoot "/data/www/blog"
ServerName blog.abc.com
ServerAlias blog1.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
[root@Centos extra]# ../../bin/apachectl -t
Syntax OK
[root@Centos extra]# ../../bin/apachectl graceful
表明別名配置也是正確的
以上是“LAMP架構(gòu)中Apache服務(wù)基于端口虛擬主機(jī)配置的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。