Apache configures multi-domain or multi-port mapping

Apache under CentOS configures multiple domain names or multiple port mappings
. The default root directory of Apache under CentOS is /var/www/html. If I save a CI project in the html folder by default, and the server's external network IP is ExampleIp, because I use It is the MVC framework, and Apache needs to enable the redirection function.

The /etc/httpd/conf/httpd.conf file is configured 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, use "service httpd restart" to restart Apache, then enter http://ExampleIp directly in the browser, and it will be directly mapped to the /var/www/html/CI folder

1. Configure multi-domain mapping. Suppose you need to map the two domain names www.website1.com and www.website1.com, add 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. Use "service httpd restart" to restart Apache after configuration

2. Configure multi-port mapping.

2.2. First, you need to monitor the port. Add the port to be monitored under Listen 80 in the document 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>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324495671&siteId=291194637