Apache configures multi domain or multi port mapping

Posted by chadtimothy23 on Fri, 03 Apr 2020 19:43:37 +0200

Apache configures multi domain or multi port mapping under CentOS
Under CentOS, the root directory of Apache's default website is / var/www/html. If I save a CI project in the html folder by default, and the server's Internet IP is ExampleIp, because the MVC framework is used, Apache needs to enable the redirection function.

/The configuration of etc/httpd/conf/httpd.conf file is as follows:

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>

After configuration, restart Apache with "service httpd restart", then enter it directly in the browser http://ExampleIp , directly mapped to the / var/www/html/CI folder

1. Configure multiple domain name mapping. Suppose you need to map the domain names www.website1.com and www.website1.com, and add them at the end of the document 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 and website2 are project directories. After configuration, restart Apache with "service httpd restart"

2. Configure multi port mapping.

2.2. First, you need to listen to the port. Add the port to listen to under Listen 80 in httpd.conf, for example, 8080

Listen 80
Listen 8080
2.2 add port mapping function at the end of the document

<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>

Topics: Apache CentOS