• notice
  • Congratulations on the launch of the Sought Tech site

How to configure a virtual machine in an Apache server

Apache's virtual host is to execute multiple websites on one server. Each virtual host can be tied to an independent domain name, and a separate directory can be specified for these domain names. When accessing these domain names, Apache will open the corresponding directory. thing. To configure the Apache virtual host, you only need to modify the Apache configuration file. The English of virtual host is virtual host, so your Apache configuration file for virtual host may be httpd.conf, or it may be a file related to the name of virtual host, such as vhost.conf, which configuration file to use, you You need to judge for yourself.

Sina Weibo virtual machine development configuration steps and introduction.

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

Added mod_rewrite.so mod support. Remove the preceding # sign from the following lines.

LoadModule rewrite_module modules/mod_rewrite.so

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

Copy the code The code is as follows:
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

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

Copy the code The code is as follows:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Save and exit.

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

Remove the example configuration and add a new configuration. Taking 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 email
ServerAdmin [email protected]
#Project root directory
DocumentRoot "D:/htdocs/frame_export"
#domain name
ServerName test.t.sina.com.cn
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 rules, can be added according to actual needs
RewriteRule ^/(.*)$ /apps/index.php [L]

4. Edit the local host file, taking windows as an example

Go to C:/Windows/System32/drivers/etc

Notepad to open the hosts file

last added localhost test.t.sina.com.cn


# 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
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# rhino.acme.com # source server
# x.acme.com # x client host
# localhost name resolution is handled within DNS itself. localhost
# ::1 localhost test.t.sina.com.cn

save and exit

5. Restart apache and enter http://test.t.sina.com.cn in the browser

About the configuration of apache virtual machine server, I will introduce so much to you, I hope it will be helpful to you!


Technical otaku

Sought technology together

Related Topic


Leave a Reply