How to configure virtual hosts with multiple ports in apache in linux

Source: Internet
Author: User

By default
The default document directory is/var/www.
Default port: 80
To publish a system resource directory, run 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-me
# Vim default-me
The file content is as follows:
Copy codeThe Code is 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 the access is normal, the configuration is correct.Copy codeThe Code is as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# Machine you can setup VirtualHost containers for them. Most deployments
# 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
# <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-nongye
ServerName www.dede.com
ErrorLog D:/AppServ/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/errornon1_5110.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-nongjiale
ServerName www.dede.com
ErrorLog D:/AppServ/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 "log/dummy-host2.x-error.log"
CustomLog "logs/dummy-host2.x-access.log" common
</VirtualHost>

1. Single Domain Name and single port settings
For example, www.abc.com is accessed by 80 by default.

Note: apache configuration is in the conf directory of the installation directory by default.
Or/etc/apache2
However, be sure to check whether port listening is enabled in the listen. conf file.
For example, port 80 listening is enabled.

Direct default
1. Single Domain Name and single port settings
For example, www.abc.com is accessed by 80 by default.

Note: apache configuration is in the conf directory of the installation directory by default.
Or/etc/apache2
However, be sure to check whether port listening is enabled in the listen. conf file.
For example, port 80 listening is enabled.
Direct default modification default-server.conf

This configuration is easier.
After the installation is complete, it can be used by default. You just need to change it to the domain name and access path you need.

Let's get a standard configuration.Copy codeThe Code is as follows: DocumentRoot "/srv/www/htdocs"
#
# Configure the DocumentRoot
#
<Directory "/srv/www/htdocs">
# Possible values for the Options directive are "None", "All ",
# Or any combination:
# 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. Configure multiple ports for a Single Domain Name
Copy codeThe Code is as follows: <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
Copy codeThe Code is as follows: <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>

Note that the listen. conf file must be used to enable multi-port listening.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.