Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure multiple sites with Apache Web server

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to configure multiple sites with Apache Web server". In daily operation, I believe many people have doubts about how to configure multiple sites with Apache Web server. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to configure multiple sites with Apache Web server". Next, please follow the editor to study!

Name-based virtual host

With a name-based virtual host, you can use a single IP address for multiple sites. Modern Web servers, including Apache, use the hostname portion of the specified URL to determine which virtual Web host responds to page requests. This only requires more configuration than a site.

Even if you only start with a single site, I suggest you set it as a virtual host so that you can add more sites more easily in the future. In this article, I'll start from where we left off in the previous article, so you need to set up the original site, the name-based virtual site.

Prepare the original site

Before setting up the second site, you need to provide name-based hosting for existing sites. If you don't have a site right now, please go back and create one immediately.

Once you have a site, add the following to the bottom of the / etc/httpd/conf/httpd.conf configuration file (this is the * change you need to make to the httpd.conf file):

DocumentRoot / var/www/html ServerName www.site1.org

This will be * virtual host configuration sections, and it should remain * to make it the default definition. This means that HTTP access to the server through the IP address or other name that resolves to this IP address but does not have a specific named host configuration section will be directed to this virtual host. All other virtual host configuration sections should follow this section.

You also need to use the entries in / etc/hosts to set up your website to provide name resolution. Last time, we only used the IP address of localhost. Typically, this can be done using any name service you use, such as Google or Godaddy. For your test site, do this by adding a new name to the localhost line in / etc/hosts. Add entries for two websites so that you don't have to edit this file again. The results are as follows:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 www.site1.org www.site2.org

Let's make the / var/www/html/index.html file a little more obvious. It should look like this (with some extra text to identify this as site 1):

Hello World Web site 1.

Restart the HTTPD server with changes to the httpd configuration enabled. You can then view the site using Lynx text mode from the command line.

[root@testvm1 ~] # systemctl restart httpd [root@testvm1 ~] # lynx www.site1.org Hello World Web site 1.Commands: Use arrow keys to move,'?' For help,'Q'to quit,'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report