How do I configure a virtual machine in an Apache server

  • 2020-05-10 23:21:04
  • OfStack

The virtual host of Apache is running multiple websites on a server, each virtual host can bind independent domain names, for these domain names can be designated a separate directory, access to these domain names, Apache will open the corresponding directory inside things. To configure Apache's virtual host, you only need to modify Apache's configuration file. The English name of virtual host is virtual host, so the file of your Apache configuration virtual host may be httpd.conf, or it may be the file related to the name virtual host, such as vhost.conf. You have to decide which configuration file to use.


Sina weibo virtual machine development and configuration steps and introduction.

1. Since Rewrite is needed in the later virtual machine, edit the httpd.conf file in the conf directory of Apache. (can be operated according to actual needs)

Add mod_rewrite.so module support. Remove the # in front of the following lines.

LoadModule rewrite_module modules/mod_rewrite.so

2. Configure apache to support virtual machines. This step is important.


# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

Find the relevant text above and remove the # before #Include conf/extra/ httpd-vhosts.conf.


# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Save to exit.

3. Edit httpd-vhosts.conf in the extra folder in the conf directory.

Remove the instance configuration and add a new one. Take sina weibo as an example, the configuration file is as follows:


#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# 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 at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# 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 *:80
#
# 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 <VirtualHost> block.
#

<VirtualHost *:80>
# Administrator mailbox 
ServerAdmin jiangfeng3@staff.sina.com.cn 
# Project root directory  
DocumentRoot "D:/htdocs/frame_export" 
# The domain name  
ServerName test.t.sina.com.cn 
# The alias  
ServerAlias test.t.sina.com.cn
# Error log path 
ErrorLog "logs/test.t.sins.com.cn-error.log"
CustomLog "logs/test.t.sins.com.cn-access.log" common
RewriteEngine on
# Rewrite the rule to add as needed 
RewriteRule ^/(.*)$ /apps/index.php [L]
</VirtualHost>

4. Edit local host files, taking windows as an example

Enter C: / Windows System32 / drivers/etc

Notepad opens the hosts file

Finally add

127.0.0.1 localhost
127.0.0.1 test.t.sina.com.cn

Example:


# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 test.t.sina.com.cn

Save the exit

5, restart apache, browser input http: / / test t. sina. com. cn

About apache virtual machine server configuration this site to give you so much, I hope to help you!


Related articles: