Windows/linux site-bound domain name under Apache

Source: Internet
Author: User
Tags bind vps

The simplest of

Namevirtualhost *

ServerName Rashost.com/blog
DocumentRoot "c:/wamp/www/vpsblog/" above the configured site is vpsblog.rashost.com/, the site corresponding to the directory is "c:/wamp/www/vpsblog/", Site name and directory name you must, of course, set your own needs.

Cases


1. Sample binding:

IP address 192.168.1.100
correspond to two domains http://your domain name. com and http://bbs. your domain name. COM (level two domain name)
2. Binding process

A, open http.conf, the file location under Apache/conf, directly with a text editor to open.
b, add the following fields, located near the servername 127.0.0.1 or servername localhost:80 near below, easy to modify and understand.

The code is as follows Copy Code

<virtualhost 192.168.1.100>
DocumentRoot d:/xampp/htdocs/your domain name. com
ServerName your domain. com
</VirtualHost>
<virtualhost 192.168.1.100>
DocumentRoot d:/xampp/htdocs/your domain name. Com/bbs
ServerName BBS. your domain name. com
</VirtualHost>

This method is to specify the IP address of the host is more appropriate, but if it is dynamic access to the host of IP address problems, you can change the <virtualhost 192.168.1.100> Unified <virtualhost *:80> After this setting, Apache no longer differentiates between IP and is identified only according to ServerName and processing priority. For example, many virtual hosts require the use of CNAME to resolve domain names, then the virtual host IP may change, can not use the above configuration method, or <virtualhost *:80> to better use some


Apache site bindings under Linux VPS

Ubuntu's configuration file knowledge under Apache
Debian/ubuntu's Apache configuration file is managed the same way that Ubuntu itself is based on Debian, so many configurations are almost identical to Debian. Debian/ubuntu Apache configuration files are in the/etc/apache2 directory. /etc/apache2 has several configuration files below, and several subdirectories. /etc/apache2 The following configuration file is explained individually:

/etc/apache2/apache2.conf
Master configuration file, not proficient Apache do not modify this file
/etc/apache2/httpd.conf
This file exists to maintain compatibility, even if you are proficient in Apache, I also recommend that you do not modify this file
/etc/apache2/ports.conf
This file is used to configure the Apache listening port, and do not modify it if you are not proficient.
/etc/apache2 The following directories explain the following:

/etc/apache2/conf.d
Apache reads any files in this directory, which are part of the configuration file and do not recommend any changes to the contents of this directory.
/etc/apache2/mods-available
This directory is a few fragmented configuration files, not recommended to modify, Apache does not read the files in this directory. The files in this directory are typically a configuration file for an Apache module
/etc/apache2/mods-enabled
Apache reads any files in this directory, which are part of the configuration file and do not recommend any changes to the contents of this directory. The files in this directory are typically a configuration file for an Apache module
/etc/apache2/sites-available
This directory is a number of fragmented configuration files, do not recommend changes, Apache will not read the files in this directory, the directory under the file is generally a site configuration file
/etc/apache2/sites-enabled
Apache reads any file in this directory, which is part of the configuration file, and does not recommend modifying anything in this directory, which is typically a site profile
As you can see from the list above, the difference between the mods-available and mods-enabled is whether Apache is going to read the directory. There's a question: if Apache never reads the mods-available directory, what does it do? The answer is to store all of the Apache module configuration files under Mods-available, but these modules are not necessarily active, the activated module's configuration file is linked to the mods-enabled below, if not linked to mods-enabled below, That must be some modules that are not activated. The a2enmod command can list all the modules under Mods-available, the administrator can choose which module to activate, and the module after the activation will add a link under mods-enabled.

Similarly, the sites-available and sites-enabled directories are also the same principle that A2ensite commands can list the site files that exist under Sites-available. You can create a link to a site file in the sites-enabled directory.

A2enmod = = Apache2 ENable MODule
A2ensite = = Apache2 ENable SITE

By default, only one file Default,sites-available/default linked to the sites-enabled directory under Sites-available is named 000-default. Apache Custom is a site of a configuration file, but we for the convenience of management, all the site configuration is saved to the file default.

How to create a new site

1. Determine the new site's domain name and alias, domain name is necessary, alias can not, alias is domain name, but not the main domain name just. For example My site domain name is rashost.com, alias has two, respectively is rashost.com and home.rashost.com.
2. Change DNS of domain name and alias, resolve to IP address of VPS. For example, to Rashost.com's domain registrar's Control Panel to modify the above three DNS records, all point to the IP address of my VPS.
3. Waiting for the domain name change to take effect, this process is usually 0-48 hours. Run ping command to see whether the domain name point to change over, such as: Ping rashost.com, if the IP displayed is a VPS IP, it means that the effective
4. With root user ssh login to the VPS, run the command to create a new user: AddUser rashost.com, change Password: passwd rashost.com. Modify the/etc/apache2/sites-available/default file to run/etc/init.d/apache2 force-reload restart Apache after adding the following configuration at the end of the file
5. Login to VPS with new user rashost.com, Run command mkdir public_html create public_html Directory
6. Through FTP, the Web page file is transferred to the public_html directory
7. Then you can access the new site through the browser

The code is as follows Copy Code

ServerName 111cn.net
Serveralias rashost.com home.rashost.com
documentroot/home/rashost.com/public_html/


So how do you bind multiple sites in Linux?


For example: The IP of the VPS is 94.249.188.58, need to bind 111cn.net to/var/www/html/dir1, bind Wuleilei.net to/var/www/html/dir2.

Open http.conf:

1, will #servername www.example.com:80 modified into ServerName 94.249.188.58:80, pay attention to don't forget to the first sentence of the # remove;

2, will #namevirtualhost *:80 modified into Namevirtualhost 94.249.188.58:80, pay attention to don't forget to the first sentence of the # remove;

3, at the end of the file has a virtual host format:

Code

The code is as follows Copy Code
1.#<virtualhost 94.249.188.58:80>
2.# ServerAdmin webmaster@dummy-host.example.com
3.# documentroot/www/docs/dummy-host.example.com
4.# ServerName dummy-host.example.com
5.# ErrorLog Logs/dummy-host.example.com-error_log
6.# Customlog Logs/dummy-host.example.com-access_log Common
7.#</virtualhost>

To add later:

The code is as follows Copy Code
1.*IP access to/var/www/html/dir directory
<virtualhost 94.249.188.58:80>
2. ServerAdmin webmaster@dummy-host.example.com
3. Documentroot/var/www/html/dir
4. ServerName 94.249.188.58
5. ErrorLog Logs/dummy-host.example.com-error_log
6. Customlog Logs/dummy-host.example.com-access_log Common
7.</virtualhost>

8.*111cn.net and www.111cn.net Access/var/www/html/dir1 directory

The code is as follows Copy Code

9.<virtualhost 94.249.188.58:80>
ServerAdmin webmaster@dummy-host.example.com

Documentroot/var/www/html/dir1.

ServerName 111cn.net
Serveralias www.111cn.net
ErrorLog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
16.</virtualhost>

17.*wuleilei.net and www

. wuleilei.net access to/var/www/html/dir2 directory

The code is as follows Copy Code

18.<virtualhost 94.249.188.58:8081>
ServerAdmin webmaster@dummy-host.example.com
Documentroot/var/www/html/dir2
ServerName wuleilei.net

Serveralias www.wuleilei.net
ErrorLog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
25.</virtualhost>

Attached: If you want to open a different port, follow these steps (take 8080 ports for example):

1, open http.conf, find listen 80, add listen 8080 in the following line;

2, add the following code at the end of the file:

Code

The code is as follows Copy Code

1.<virtualhost 94.249.188.58:8080>
2. ServerAdmin webmaster@dummy-host.example.com
3. Documentroot/var/www/html/dir3

4. ServerName 111cn.net
5. Serveralias Www.111cn.net
6. ErrorLog Logs/dummy-host.example.com-error_log
7. Customlog Logs/dummy-host.example.com-access_log Common
8.</virtualhost>

This binds the www.111cn.net:8080 to the/VAR/WWW/HTML/DIR3 directory.

Related Article

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.