How to configure a virtual host using multiple ports in apache in linux

Source: Internet
Author: User
In linux, apache provides an in-depth description of how to configure virtual hosts with multiple ports. By default, the default document directory used by apache in linux is: varwww default port is: 80. if you want to publish your own system resource directory, you can use the following method, run
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:

The code is as follows:


8000>
ServerAdmin webmaster @ localhost
DocumentRoot/ Wwwroot

Options FollowSymLinks
AllowOverride None

Wwwroot/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow, deny
Allow from all

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


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.

The 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
#
# 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 Block.
#

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



Options FollowSymLinks
# Deny from all
Allow from all

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


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


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


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


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


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


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


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.

The code is as follows:


DocumentRoot "/srv/www/htdocs"
#
# Configure the DocumentRoot
#

# 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


2. configure multiple ports for a single domain name

The code is as follows:



Options None
AllowOverride None
Order allow, deny
Allow from all


Options None
AllowOverride None
Order allow, deny
Allow from all

NameVirtualHost *: 80
NameVirtualHost *: 81

DirectoryIndex index.html index. php
ServerName "www.abc.com"
DocumentRoot "/srv/www/htdocs /"


DirectoryIndex index. php
ServerName "www.abc.com: 81"
DocumentRoot "/srv/www/htdocs/bbs /"


3. multi-domain and multi-port settings

The code is as follows:



Options None
AllowOverride None
Order allow, deny
Allow from all


Options None
AllowOverride None
Order allow, deny
Allow from all


Options None
AllowOverride None
Order allow, deny
Allow from all

NameVirtualHost *: 80
NameVirtualHost *: 81

DirectoryIndex index.html index. php
ServerName "www.abc.com"
DocumentRoot "/srv/www/htdocs /"


DirectoryIndex index.html index. php
ServerName "www.btc.com"
DocumentRoot "/srv/www/htdocs/btc"


DirectoryIndex index. php
ServerName "www.abc.com: 81"
DocumentRoot "/srv/www/htdocs/bbs /"


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

The default document directory for release is/var/www. the default port is: 80. if you want to publish your own system resource directory, you can use the following method to execute it, as shown in...

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.