這篇文章主要介紹“CentOS系統下Apache怎么配置多域名或多端口映射”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“CentOS系統下Apache怎么配置多域名或多端口映射”文章能幫助大家解決問題。
前提
centos下apache默認網站根目錄為/var/www/html,假如我默認存了一個ci項目在html文件夾里,同時服務器的外網ip為exampleip,因為使用的是mvc框架,apache需開啟重定向功能。
方法如下
/etc/httpd/conf/httpd.conf文件配置如下:
documentroot "/var/www/html/ci"
<directory /> options followsymlinks allowoverride all </directory>
<directory "/var/www/html/ci"> # # possible values for the options directive are "none", "all", # or any combination of: # indexes includes followsymlinks symlinksifownermatch execcgi multiviews # # note that "multiviews" must be named *explicitly* --- "options all" # doesn't give it to you. # # the options directive is both complicated and important. please see # /tupian/20230522/core.html # for more information. # options indexes followsymlinks # # allowoverride controls what directives may be placed in .htaccess files. # it can be "all", "none", or any combination of the keywords: # options fileinfo authconfig limit # allowoverride all # # controls who can get stuff from this server. # order allow,deny allow from all </directory>
配置完使用“service httpd restart”重啟apache,那么直接在瀏覽器里輸入http://exampleip,就直接映射到/var/www/html/ci文件夾里了
1、配置多域名映射。假設需要映射www.website1.com和www.website1.com這兩個域名,在文檔httpd.conf最后添加
namevirtualhost *:80 <virtualhost *:80> documentroot /var/www/html/website1 servername http://www.website1.com </virtualhost> <directory "/var/www/html/website1"> options indexes followsymlinks allowoverride all order allow,deny allow from all </directory> <virtualhost *:80> documentroot /var/www/html/website1 servername http://website1.com </virtualhost> <directory "/var/www/html/website1"> options indexes followsymlinks allowoverride all order allow,deny allow from all </directory> <virtualhost *:80> documentroot /var/www/html/website2 servername http://www.website2.com </virtualhost> <directory "/var/www/html/website2"> options indexes followsymlinks allowoverride all order allow,deny allow from all </directory> <virtualhost *:80> documentroot /var/www/html/website2 servername http://website2.com </virtualhost> <directory "/var/www/html/website2"> options indexes followsymlinks allowoverride all order allow,deny allow from all </directory>
website1和website2為工程目錄.配置完使用“service httpd restart”重啟apache
2、配置多端口映射。
2.2、首先需要監聽端口,在文檔httpd.conf的listen 80下添加需要監聽的端口,舉例為8080
listen 80 listen 8080
2.2、在文檔最后添加端口映射功能
<virtualhost exampleip:8080> documentroot /var/www/html/website3 servername exampleip:8080 </virtualhost> <directory "/var/www/html/website3"> options indexes followsymlinks allowoverride all order allow,deny allow from all </directory>
website3為工程目錄.配置完使用“service httpd restart”重啟apache
關于“CentOS系統下Apache怎么配置多域名或多端口映射”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注創新互聯行業資訊頻道,小編每天都會為大家更新不同的知識點。
文章標題:CentOS系統下Apache怎么配置多域名或多端口映射-創新互聯
標題URL:http://vcdvsql.cn/article34/cscspe.html
成都網站建設公司_創新互聯,為您提供手機網站建設、網站排名、網站改版、域名注冊、定制開發、搜索引擎優化
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯