linux Environment apache multi port configuration virtual host method in depth

  • 2020-06-12 08:34:55
  • OfStack

By default, apache is used on linux
The default document directory is: /var/www
The default port is 80
If you want to publish your own system resource directory, you can use the following method and execute the following command:
(1) Add a listening port
#cd /etc/apache2
#vim ports.conf
File addition:
NameVirtualHost *:8000
Listen 8000
(2) Configure the virtual directory
#cd /etc/apache2/sites-available
#cp default default-me
#vim default-me
The file contents are as follows:

<VirtualHost *:8000 >
    ServerAdmin webmaster@localhost
    DocumentRoot /wwwroot
    <Directory / >
Options FollowSymLinks
AllowOverride None
    </Directory>
    <Directory /wwwroot/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
</VirtualHost>

The bold part is the key point.
(3) Release site
# ln -s /etc/apache2/sites-available/default-me /etc/apache2/sites-enabled/001-default
(4) Restart the service
#/etc/init.d/apache2 restart
(5) test
http://localhost:8000/
If you can access it correctly, you are configured correctly.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/ >
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:81
NameVirtualHost *:82
NameVirtualHost *:83
NameVirtualHost *:84
NameVirtualHost *:85
NameVirtualHost *:86
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:81>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-nongye
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-nongye/errornongye.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:82>
<Directory "D:/AppServ/www-chinaec" >
Options FollowSymLinks
#Deny from all
Allow from all
</Directory>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www-chinaec
ServerName www.dede.com
DirectoryIndex index.php index.html
ErrorLog D:/AppServ/www-chinaec/errornongjiale.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:83>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-05110
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-05110/errornong05110.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:84>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/wordpress
ServerName www.dede.com
ErrorLog D:/AppServ/www/wordpress/errornongwordpress.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:85>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/magento
ServerName www.dede.com
ErrorLog D:/AppServ/www/magento/errormagento.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:86>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/magento1322
ServerName www.dede.com
ErrorLog D:/AppServ/www/magento1322/errormagento1322.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:88>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-nongjiale
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-nongjiale/errornongjiale.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.x
DocumentRoot "C:/Apache2.2/docs/dummy-host2.x"
ServerName dummy-host2.x
ErrorLog "logs/dummy-host2.x-error.log"
CustomLog "logs/dummy-host2.x-access.log" common
</VirtualHost> 

1. Single-domain list port setting
For example: ES42en. abc. com default to use 80 access

In particular, the apache configuration defaults to the conf directory under the installation directory
Or is/etc apache2
Note, however, that the port listening in the listen.conf file is enabled
The figure below indicates that port 80 listening is enabled

The default directly
1. Single-domain list port setting
www. abc. com is accessed with 80 by default

In particular, apache is configured by default in the conf directory under the installation directory
Or is/etc apache2
Note, however, that port listening in the ES71en.conf file is enabled or not
The figure below indicates that port 80 listening is enabled
default-server.conf is modified directly by default

This configuration is best simple
Once installed, the default is ready to use, just change it to your desired domain name and access path.

Give me a standard configuration

DocumentRoot "/srv/www/htdocs"
#
# Configure the DocumentRoot
#
<Directory "/srv/www/htdocs">
# 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 None
# 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 None
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
</Directory>

2. Single-domain multi-port Settings

<Directory "/srv/www/htdocs/bbs">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/srv/www/htdocs/">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
NameVirtualHost   *:80
NameVirtualHost   *:81
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   "www.abc.com "
  DocumentRoot   "/srv/www/htdocs/"  
  </VirtualHost>
<VirtualHost *:81>
  DirectoryIndex   index.php
    ServerName   "www.abc.com:81 "
  DocumentRoot   "/srv/www/htdocs/bbs/"  
  </VirtualHost>

3. Multi-domain and multi-port Settings

<Directory "/srv/www/htdocs/btc">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/srv/www/htdocs/bbs">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/srv/www/htdocs/">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
NameVirtualHost   *:80
NameVirtualHost   *:81
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   "www.abc.com "
  DocumentRoot   "/srv/www/htdocs/"  
  </VirtualHost>
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   "www.btc.com "
  DocumentRoot   "/srv/www/htdocs/btc"  
  </VirtualHost>
<VirtualHost *:81>
  DirectoryIndex   index.php
    ServerName   "www.abc.com:81 "
  DocumentRoot   "/srv/www/htdocs/bbs/"  
  </VirtualHost>

The important thing to note is that the multi-port listening, 1 must pay attention to the listen.conf file, whether the corresponding port is turned on.

Related articles: