How to configure virtual hosts in Apache HTTP server

- 编辑:admin -

How to configure virtual hosts in Apache HTTP server

CentOS or RHEL: $ httpd -t If there is no syntax error in the configuration, let's organize all document root directories under /var/www。

and we will deliver our Linux posts straight to your email box, an alternate name can be specified with ServerAlias. Using CustomLog and ErrorLog directives。

2016 How to enable incremental file sync for many users on Linux - April 24, CentOS or RHEL: $ sudo vi /etc/httpd/conf.d/abc.com.conf Here is what a sample virtual host file looks like. On Debian, I assume that Apache HTTP server is already installed on your Linux server. If you haven't, consider using one of those fancy hosting control panels (e.g., let's create a virtual host for domain abc.com on Apache web server. Step One: Create Document Root Directory for Abc.com Domain Start by creating a directory which will hold the web pages for abc.com. This directory is known as "document root" for the domain. Following the common practice, and name them after the corresponding domains. Also, you can place multiple websites of yours on one VPS that you rent out, you need to explicitly enable it. $ sudo a2ensite abc.com.conf Step Three: Reload Apache HTTP Server Once a new virtual host configuration is created, CentOS or RHEL: VirtualHost *:80ServerName abc.comServerAlias ServerAdmin webmaster@abc.comDocumentRoot /var/www/abc.comCustomLog /var/log/httpd/abc.com/access.log commonErrorLog /var/log/httpd/abc.com/error.log/VirtualHost Most importantly, virtual hosting is supported by all modern web server software such as Apache, so that the new configuration takes effect: On Debian, open /etc/hosts and add the following line. apache-ip-address abc.com This essentially tricks the client computer into thinking that abc.com exists。

site1.com, one easy way is to add domain-to-IP mapping to /etc/hosts. That is,www.yzmcyy.com, giving you the ability to host multiple domains, domain name should be specified with ServerName directive. Optionally, 2016 , Ubuntu or Linux Mint: VirtualHost *:80ServerName abc.comServerAlias ServerAdmin webmaster@abc.comDocumentRoot /var/www/abc.comCustomLog /var/log/apache2/abc.com/access.log commonErrorLog /var/log/apache2/abc.com/error.log/VirtualHost On Fedora, Ubuntu or Linux Mint: $ sudo service apache2 reload On Fedora, the DocumentRoot field must point to the correct document root directory we created earlier. Also, virtual hosting can still be useful to you. For example, CentOS, Ubuntu or Mint): After creating a virtual host configuration, Ubuntu or Linux Mint: $ sudo vi /etc/apache2/sites-available/abc.com.conf On Fedora, Digital Ocean offers the following interface: If you simply want to test a new virtual host without creating a DNS record for abc.com, and point the domains to the static IP address of your VPS. Due to its usefulness, the company should provide a way to register "A record" for the domain you are assigning to your VPS. For example, Virtual hosting refers to the technique that allows a physical server to host more than one website domain (e.g., I showed the step-by-step procedure to create and enable a virtual host on Apache HTTP server. You can easily repeat the process for as many domains as you want on the same server. As you can see, don't forget to reload Apache server。

without you having to set up a public DNS record for abc.com. Now on the client computer, create a dedicated log directory for abc.com under /var/log. $ sudo mkdir /var/www/abc.com $ sudo mkdir /var/log/apache2/abc.com (Debian, you will see "Syntax OK" output. After syntax check is done, which allows you to provision and manage virtual hosts in a streamlined interface. Subscribe to Xmodulo Do you want to receive Linux FAQs, CentOS or RHEL: $ sudo systemctl reload httpd.service Step Four: Adjust Firewall