CentOS server apache binds multiple domain name methods

  • 2020-05-13 04:19:06
  • OfStack

Apache is one of the most popular HTTP server software. It is known for its speed, reliability, and stability, and can be compiled to the server with a simple API extension. The Perl/Python interpreters are completely free and open source. If you have your own server or VPS and don't want to buy expensive control panels for convenience, then configuring Apache yourself is a required course. The following is a brief description of how to bind multiple domain names and their associated level 2 domains by setting the http.conf file of Apache (suppose we are binding minidx.com and ntt.cc, level 2 is blog.minidx.com, and independent IP is 72.167.11.30).

How does apache bind multiple domain names

Open the http conf

1. ServerName 127.0.0.1 was modified to ServerName 72.167.11.30

2. Change #NameVirtualHost * to "NameVirtualHost 72.167.11.30"

3. There is a virtual host format at the end of the file:


#<VirtualHost *>
#  ServerAdmin [email]admin@minidx.com[/email]
#  DocumentRoot /www/httpd/html/minidx.com
#  ServerName minidx.com
#  ErrorLog logs/minidx.com-error_log
#  CustomLog logs/minidx.com-access_log common
#</VirtualHost>
// Simple addition: 
<VirtualHost 72.167.11.30>
 DocumentRoot usr/local/www/
 ServerName  72.167.11.30
</VirtualHost>
<VirtualHost 72.167.11.30>
 DocumentRoot usr/local/www/minidx.com/
 ServerName  minidx.com
</VirtualHost>
<VirtualHost 72.167.11.30>
 DocumentRoot  usr/local/www/ntt.cc/
 ServerName  ntt.cc
</VirtualHost>

Log files can also be added in their own path.

How to add a level 2 domain name to Apache

In httpd.conf, the mod_rewrite function needs to be turned on (for the detailed explanation of URL redirection, please refer to the summary of how to use htaccess). The specific operation is to add the following content at the end of httpd.conf:

RewriteEngine on

RewriteMap lowercase int:tolower

RewriteMap vhost txt:/usr/local/etc/apache/vhost.map

RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$

RewriteCond ${vhost:%1} ^(/.*)$

RewriteRule ^/(.*)$ %1/$1

The usr/local etc/apache is your apache server configuration file path, according to the actual situation changes (for example) under/etc/httpd /. Then, create a file: vhost.map in the directory of this path. The content is:

www.minidx.com /usr/local/www/minidx.com

www.ntt.cc /usr/local/www/ntt.cc

blog.minidx.com /usr/local/www/minidx.com/blog

Finally, under the root directory /usr/local/www/, create the corresponding directory. If you need to add, modify, or delete a domain name or subdomain, you only need to change the vhost.map file without restarting the apache process.

. Summary of the usage method of htaccess

By Minidxer | January 26, 2008

The use of.htaccess redirection is already mentioned in the pseudo-static linking of Discuz forums using the Rewrite rule of.htaccess. Let's take a more comprehensive look at.htaccess. .htaccess is a very powerful distributed configuration file for the Apache server. The correct understanding and use of.htaccess files can help us optimize our own servers or virtual hosts. For example, you can use the.htaccess file to create a custom "404 error" page and change the configuration of many servers. All we need to do is add a few simple instructions to this text document.

Unix or Linux systems, or any version of Apache Web services, support.htaccess, but some hosting providers may not allow you to customize your own.htaccess files. Foreign current mainstream virtual host providers, almost all support custom functions.

To enable.htaccess, you need to modify httpd.conf to enable AllowOverride, and you can restrict the use of certain commands with AllowOverride

If you need to use a file name other than.htaccess, you can use the AccessFileName directive to change it. For example, if you need to use.config, you can configure it in the server configuration file as follows:

AccessFileName .config

Generally speaking,.htaccess can help us to implement some functions such as folder password protection, automatic user redirection, custom error pages, changing your file extension, blocking users with specific IP addresses, allowing users with specific IP addresses only, banning directory lists, and using other files as index files.

● create a.htaccess document

htaccess is one odd filename (from Win perspective, it has no name, only one of eight letters of extension, but it is actually linux naming, and many linux things, we always will think very strange), in Win system is not can be directly through the "new" to create a file, but we can use the copy cmd to implementation, such as copy sample. txt. htaccess. You can also create an htaccess.txt, and then Ftp goes to the server and changes the file name with FTP.

. One application of htaccess is

● custom error page

Customize the error page, which allows you to have your own, personalized error page (for example, if a file cannot be found) instead of the error page provided by your service or no page at all. This will make your site look more professional when things go wrong. You can also use scripts to notify you of errors (e.g., automatically Email when a page is not found).

Any page error code you know of (like 404 can't find a page) can be turned into a custom page by adding the following text to the.htaccess file:

ErrorDocument errornumber /file.html

For example, if I have an notfound.html file in my root directory, I want to use it as a 404 error page:

ErrorDocument 404 /notfound.html

If the file is not in the root directory of the website, you only need to set the path to:

ErrorDocument 500 /errorpages/500.html

Here are some of the most common mistakes:

401-Authorization Required requires validation

400-Bad request error request

403-Forbidden prohibited

500 - Internal Server Error internal server error

404 - Wrong page page not found

Next, all you have to do is create a file that will be displayed when an error occurs and upload it with.htaccess1.

Low. htaccess command

A list of directories is not allowed to be displayed

Sometimes, for some reason, you don't have the index file in your directory, which means that when someone types in the directory's path in the browser's address bar, all the files in that directory will appear, leaving your site vulnerable.

To avoid this (instead of creating 1 heap of new index files), you can type the following command into your.htaccess document to block it

Display of directory list:

Options -Indexes

The waddle blocks/allows specific IP addresses

In some cases, you may only want to allow certain IP users to access your site (for example, only certain ISP users can access a certain directory), or you may want to block certain IP addresses (for example, isolate low-level users from your message board). Of course, this is only useful if you know the IP address you want to intercept, but most users on the web now use dynamic IP addresses, so this is not a common way to restrict use.

You can block 1 IP address by using the following command:

deny from 000.000.000.000

Here 000.000.000.000 is the banned IP address, if you specify only a few of them, you can block the entire segment of the network address. If you enter 210.10.56., all IP addresses from 210.10.56.0 to 210.10.56.255 will be blocked.

You can allow 1 IP address to access the site using the following command:

allow from 000.000.000.000

The permitted IP address is 000.000.000.000, and you can block the entire segment as if you were blocking IP address 1.

If you want to prevent everyone from accessing the directory, you can use:

deny from all

However, this does not prevent scripts from using the documents in this directory.

And replace the index file

You may not want to use index.htm or index.html as index files for the directory. For example, if your site USES the PHP file, you might want to use index.php as an index document for that directory. Of course, you don't have to limit yourself to "index" documents; you can even set foofoo.balh as your index document, if you prefer, with.htaccess!

These alternate index files can be arranged into a single list, and the server will search from left to right to check which documents exist in the real directory. If none is found, it will display the directory list (unless you have turned off the display directory file list).

DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm

Wok redirection (rewrite)

One of the most useful functions of.htaccess is to redirect requests to different documents on or off the same site. This becomes extremely useful when you change the name of a file but still want users to access it from the old address. Another application (which I found useful) was to redirect to a long URL, for example, in my newsletter, I could use a very short URL to point to my membership link. Here is an example of a redirected file:

Redirect/location/from/root/file ext http: / / minidx com new/file/location xyz

In the example above, to access the name oldfile.html in the root directory, type: / oldfile.html

To access a file in an old subdirectory, type: /old/ oldfile.html

You can also use.htaccess to redirect the entire site directory. If your website has a directory called olddirectory, and you have a new website http: / / minidx com newdirectory/set up with the same document, you can take all the old directory file to do 1 time redirect instead of 11 statement:

Redirect/olddirectory http: / / minidx com/newdirectory

Thus, any requests to the /olddirectory directory at the site will be redirected to the new site, including additional URL information. For example, someone types in:

http: //minidx.com/olddirecotry/oldfiles/images/image.gif

The request will be redirected to:

http: //minidx.com/newdirectory/oldfiles/images/image.gif

This can be extremely powerful if used correctly.

Note: since Windows Live Writer will automatically add a hyperlink when editing this article when it encounters http://, a space has been added, which was not there.

● password protection

Although there are various USES of.htaccess, by far the most popular and probably most useful is to use it for secure password protection of a website directory. Although JavaScript and others can do the same, only.htaccess has perfect security (that is, visitors must know the password to access the directory and there is no "back door").

There are two steps to password protection for a directory using.htaccess. Step 1 is to add the appropriate lines of code to your.htaccess document, and then put the.htaccess document into the directory you want to protect:

AuthName "Section Name"

AuthType Basic

AuthUserFile /full/path/to/.htpasswd

Require valid-user

You may need to modify 1 part of the above according to your site, such as replacing "Section Name" with the name of the protected part "Members Area".

/ full/parth/to /. htpasswd should replace to point to. htpasswd file detailing the documentation (behind) the complete server path. If you don't know the full path to your webspace, ask your system administrator.

Password protected.htpasswd file

Directory password protection is a little trickier than the other features of.htaccess, because you must create a document containing both your username and password to access your site, and the information (by default) is in a document called.htpasswd. Like.htaccess1,.htpasswd is also a document with no file name and an 8-bit extension that can be placed anywhere on your site (the password should be encrypted at this point), but it is recommended that you save it outside the site's Web root so that it is not accessible over the network.

Once you have created the.htpasswd document (which can be created through a text editor), the next step is to enter the username and password for accessing the site, which should be:

username:password

The location of "password" should be the encrypted password. You can get encrypted passwords by using one of the permade scripts available on the web or by writing one yourself. Another great username/password encryption service is through the KxS website, which allows you to enter your username and password, and then generate a password in the correct format. For multiple users, you only need to add 1 line of the same format to the.htpasswd document. In addition, there are some free scripts that can easily manage.htpasswd documents and automatically add/remove users.

When you try to access a directory protected by the.htaccess password, your browser will pop up the standard username/password dialog window. If you don't like this way, some script that allows you to embedded within the page username/password input box for certification, you can also in the browser's URL box enter the user name and password in the following way: (unencrypted) http: / / username: password@www.website.com/directory /

If you want to know more about the use of htaccess, you can refer to the relevant documents in doc of Appache.


Related articles: