CentOS系統(tǒng)下Apache配置多域名或多端口映射的方法
前提
CentOS下Apache默認(rèn)網(wǎng)站根目錄為/var/www/html,假如我默認(rèn)存了一個(gè)CI項(xiàng)目在html文件夾里,同時(shí)服務(wù)器的外網(wǎng)IP為ExampleIp,因?yàn)槭褂玫氖荕VC框架,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 # http://httpd.apache.org/docs/2.2/mod/core.html#options # 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、配置多域名映射。假設(shè)需要映射www.website1.com和www.website1.com這兩個(gè)域名,在文檔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、首先需要監(jiān)聽端口,在文檔httpd.conf的Listen 80下添加需要監(jiān)聽的端口,舉例為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
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
- 詳解apache配置域名的坑
- 詳解在Ubuntu上的Apache配置SSL(https證書)的正確姿勢(shì)
- win10 apache配置虛擬主機(jī)后localhost無法使用的解決方法
- MAC下通過改apache配置文件切換php多版本的方法
- 修改Apache配置指定php配置文件php.ini的位置方法
- thinkphp Apache配置重啟Apache1 restart 出錯(cuò)解決辦法
- 非集成環(huán)境的php運(yùn)行環(huán)境(Apache配置、Mysql)搭建安裝圖文教程
- Ubuntu Apache配置以及cgi配置方法
- Apache偽靜態(tài)(Rewrite).htaccess文件詳解與配置技巧
相關(guān)文章
CentOS 8.0.1905 安裝 ZABBIX4.4版本 (已驗(yàn)證)
目前CentOS8.0.1905正式發(fā)布,這篇文章主要介紹了CentOS 8.0.1905 安裝 ZABBIX4.4 (已驗(yàn)證),需要的朋友可以參考下2019-10-10Ubuntu?22.04?服務(wù)器安裝部署(nginx+postgresql)
Ubuntu?22.04?LTS?是迄今為止最好的?Ubuntu?版本之一,很多l(xiāng)inux的應(yīng)用服務(wù)器都是選擇的這個(gè)版本,所以小編最近也開始學(xué)習(xí)這個(gè)了,這里特為大家分享一下2025-03-03Linux入門之網(wǎng)絡(luò)系統(tǒng)詳解
大家好,本篇文章主要講的是Linux入門之網(wǎng)絡(luò)系統(tǒng)詳解,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12CentOS下使用LibreOffice實(shí)現(xiàn)文檔格式的轉(zhuǎn)換方式
項(xiàng)目需求,對(duì)上傳的文檔進(jìn)行一些預(yù)處理,如果用戶上傳了doc格式的文檔,需要將其處理為docx或者pdf格式,以便后續(xù)的流程對(duì)文檔內(nèi)容進(jìn)行提取。接下來通過本文給大家分享CentOS下使用LibreOffice實(shí)現(xiàn)文檔格式的轉(zhuǎn)換,感興趣的朋友一起看看吧2019-07-07Linux學(xué)習(xí)第二篇 Java環(huán)境安裝配置教程
這篇文章主要為大家詳細(xì)介紹了Linux學(xué)習(xí)第二篇,Java環(huán)境安裝配置教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05