CentOS system Apache configuration of multiple domain name or multiple port mapping method

  • 2020-05-15 03:22:22
  • OfStack

The premise

Under CentOS, the default root directory of Apache website is /var/www/html. If I save an CI project in the html folder by default, IP of the server is ExampleIp. Because the MVC framework is used, Apache needs to turn on the redirection function.

Methods the following

/ etc/httpd/conf/httpd conf file configuration 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>

Finish the configuration using the "service httpd restart" restart Apache, then directly in the browser input http: / / ExampleIp, directly mapped to/var/www/html CI folder

1. Configure multiple domain name mappings. Suppose you want to map the www.website1.com and www.website1.com domain names, which are added at the end of the httpd.conf document


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 using "service httpd restart"

Configure multi-port mapping.

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


Listen 80
Listen 8080

2.2 add port mapping 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>

website3 is the project directory. After configuration, restart Apache using "service httpd restart"

conclusion

The above is the whole content of this article, I hope the content of this article to your study or work can bring 1 definite help, if you have questions you can leave a message to communicate.


Related articles: