您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“LAMP架構中Apache服務基于端口虛擬主機配置的示例分析”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“LAMP架構中Apache服務基于端口虛擬主機配置的示例分析”這篇文章吧。
基于端口虛擬主機配置
前面介紹了基于域名、IP的虛擬主機配置,實際生產環境中使用最多的還是基于域名的虛擬主機,今天介紹的基于端口的虛擬主機也不常用,但用的最多的場景就是:公司內網(如網站后臺頁面、其它發布類的頁面)
基于端口的虛擬配置非常簡單
默認情況http默認監聽的是80端口,所以配置基于端口的虛擬主機,就是增加相應的監聽端口
一:配置之前備份配置文件
[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
二:配置站點目錄(方便測試不同端口)
[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
三:配置虛擬主機配置文件
1、配置前還需要到主配置文件中增加目錄控制權限
[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>
實際生產環境中還是使用規范路徑比較好,也可以將配置修改成如下
[root@Centos extra]# vi ../httpd.conf
<Directory "/data/www">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
對上一級目錄統一授權
2、主配置文件增加監聽端口
[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、配置虛擬主機配置文件
[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、檢查配置、重啟服務
[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
四:測試配置
[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
本地瀏覽器測試
經過測試,訪問正常,表明配置正確
五:主機別名的應用
修改下剛剛的虛擬主機配置
#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架構中Apache服務基于端口虛擬主機配置的示例分析”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。