当前位置:网站首页>What are the ways of configuring Apache virtual hosts
What are the ways of configuring Apache virtual hosts
2022-07-22 17:17:00 【Yisu cloud】
apache How to configure virtual hosts
This article mainly introduces apache What is the relevant knowledge about the way of virtual host configuration , The content is detailed and easy to understand , The operation is simple and fast , It has certain reference value , I believe that after reading this article apache There are many articles about how to configure virtual hosts , Let's have a look .
Notepad open httpd.conf file , This document is located in apache Under the directory of , Such as : D:\AppServ\Apache2.2\conf, The following two changes are made :
LoadModule vhost_alias_module modules/mod_vhost_alias.so // Get rid of the front #, It means to enable apache Virtual host function of , The first 203 That's ok
Include conf/extra/httpd-vhosts.conf // Get rid of # I mean from httpd-vhosts.conf This file imports the virtual host configuration
After configuring the virtual host Out-of-service localhost visit
Only need to httpd.conf Of documents ServerName localhost:80 Comment out that line That's all right.
One 、 be based on IP
hypothesis The server There is one IP The address is 192.168.1.10, Use ifconfig In the same network interface eth0 The binding 3 individual IP:
[[email protected] root]# ifconfig eth0:1 192.168.1.11[[email protected] root]# ifconfig eth0:2 192.168.1.12[[email protected] root]# ifconfig eth0:3 192.168.1.13
modify hosts file , Add three domain names corresponding to one of them :
192.168.1.11 www.test1.com192.168.1.12 www.test2.com192.168.1.13 www.test3.com
Set up the root directory of the web page in the virtual host , If in /www Create under directory test1、test2、test3 Folder , They are stored separately 1.html、2.html、3.html
/www/test1/1.html/www/test2/2.html/www/test3/3.html
stay httpd.conf The configuration file will be attached httpd-vhosts.conf Include , And then httpd-vhosts.conf Write the following configuration :
<VirtualHost 192.168.1.11:80> ServerName www.test1.com DocumentRoot /www/test1/ <Directory "/www/test1"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All </Directory></VirtualHost><VirtualHost 192.168.1.12:80> ServerName www.test1.com DocumentRoot /www/test2/ <Directory "/www/test2"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All </Directory></VirtualHost><VirtualHost 192.168.1.13:80> ServerName www.test1.com DocumentRoot /www/test3/ <Directory "/www/test3"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All </Directory></VirtualHost>
Be accomplished , Test each virtual host , Visit separately www.test1.com、www.test2.com、www.test3.com
Two 、 Based on host name
Set the domain name to map to the same IP, modify hosts:
127.0.0.1 gm.998gx.com127.0.0.1 www.998gx.com127.0.0.1 r.998gx.com127.0.0.1 localhost
Same as above , Set up the root directory of the web page in the virtual host
/www/dxGM/index.php/www/dxskadmin/index.php/www/88qp/index.php
stay httpd.conf The configuration file will be attached httpd-vhosts.conf Include , And then httpd-vhosts.conf Write the following configuration :
In order to use domain name based virtual hosts , Server must be specified IP Address ( And possible ports ) Make the host accept the request . It can be used NameVirtualHost Command to configure . If everything on the server IP The address will be used , You can use it. * As NameVirtualHost Parameters of . stay NameVirtualHost The Directive states that IP The address doesn't make the server automatically listen for that IP Address . It's set here IP The address must correspond to a network interface on the server .
The next step is to set the configuration block for each virtual host you create , The parameters of NameVirtualHost The parameters of the instruction are the same . In each definition block , At least there will be one ServerName Command to specify which host and one DocumentRoot Command to indicate where the contents of the host exist in the file system .
If in the existing web Add virtual host on the server , A definition block must also be built for the existing host . among ServerName and DocumentRoot The content should be consistent with the overall situation , And put it at the top of the configuration file , Play the role of default host .
<VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW/dxGM" ServerName gm.998gx.com </VirtualHost><VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW/88qp" ServerName www.998gx.com </VirtualHost><VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW/dxskadmin" ServerName r.998gx.com </VirtualHost><VirtualHost *:80> DocumentRoot "D:/phpstudy/WWW" ServerName localhost </VirtualHost>
4. Be accomplished , Test each virtual host , Visit separately gm.998gx.com、www.998gx.com、r.998gx.com
3、 ... and 、 Based on the port
Modify the configuration file
The original
Listen 80
Change it to
Listen 80
Listen 8080
Change virtual host settings :
<VirtualHost 192.168.1.10:80> DocumentRoot /var/www/test1/ ServerName www.test1.com</VirtualHost><VirtualHost 192.168.1.10:8080> DocumentRoot /var/www/test2 ServerName www.test2.com</VirtualHost>
About “apache How to configure virtual hosts ” That's all for this article , Thank you for reading ! I'm sure you're right “apache How to configure virtual hosts ” Knowledge has a certain understanding , If you want to learn more , Welcome to the Yisu cloud industry information channel .
边栏推荐
- Add asynchronous task processing model task to flask framework
- Apache自带的ab压力测试工具如何实现
- Getting started with VIM
- 使用OpenCV实现哈哈镜效果
- [red team] att & CK - browser extension for persistence
- Enthusiasm and expertise fly together | Microsoft's most valuable expert project, attracting Microsoft technology contributors!
- Pytorch optimizer: optim SGD && optimizer.zero_ grad()
- Atomicinteger class is used in multithreading to ensure thread safety
- Win11终端管理员打不开解决方法
- Can0 transceiver + receive interrupt configuration and baud rate calculation of gd32f470 (detailed)
猜你喜欢
Crack PLSQL by deleting the registry
JWT learning
LVS load balancing cluster
怎么使用js实现计算器和计时器功能
Are you still writing code for adding, deleting, modifying and checking? Direct one click generation
Thread series coordination principle
keepalived
接招吧。最强“高并发”系统设计 46 连问,分分钟秒杀一众面试者
UE4 merge static mesh body
Win11遇到问题需要重启怎么办?
随机推荐
Are you still writing code for adding, deleting, modifying and checking? Direct one click generation
Qt5.9.2 initial import using msvc2017_ 64 record of problems encountered by compiler
Abaqus实现二自由度振动系统模态计算
Hande enterprise PAAS platform hzero released version 1.5.0.release
Win11开机只有鼠标显示怎么办?
numpy.around
MySQL foundation +mysql cluster review
Pytoch deep learning practice lesson 11 (CNN)
Lepton 无损压缩原理及性能分析
Write a sequencer plug-in sequence subtitle (1)
分享我们的首次Otherside之旅
vim入门
ig,ax = plt.subplots()
电子信息工程专业毕设题目选题推荐
【机器学习】pytorch如何加载自定义数据集并进行数据集划分
Ffmpeg-rk3399 ffplay learning analysis
Hande enterprise PAAS platform hzero will soon be heavily open source!
5 minutes to talk about the enterprise PAAS platform hzero!
Classification of attention mechanism
QT warning: c4819: this file contains characters that cannot be represented in the current code page (936). Please save the file in Unicode format to prevent data loss