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
# 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、配置多域名映射。假設需要映射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配置多域名或者多端口映射


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM