In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to configure apache virtual host, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Three methods of configuring Virtual Host in Apache
Notepad opens the httpd.conf file, which is located in the apache directory, such as D:\ AppServ\ Apache2.2\ conf, with the following two modifications:
LoadModule vhost_alias_module modules/mod_vhost_alias.so / / remove the preceding #, which means to enable the virtual host function of apache, and line 203 Include conf/extra/httpd-vhosts.conf / / remove # means to import the virtual host configuration from the file httpd-vhosts.conf
Cannot be accessed with localhost after configuring virtual host
You just need to comment out the ServerName localhost:80 line of the httpd.conf file.
Based on IP
Suppose the server has an IP address of 192.168.1.10 and uses ifconfig to bind 3 IP on the same network interface eth0:
[root@localhost root] # ifconfig eth0:1 192.168.1.11 [root@localhost root] # ifconfig eth0:2 192.168.1.12 [root@localhost root] # ifconfig eth0:3 192.168.1.13
Modify the hosts file and add three domain names to correspond to it:
192.168.1.11 www.test1.com192.168.1.12 www.test2.com192.168.1.13 www.test3.com
Set up a virtual host to store the root directory of the web page, such as test1, test2 and test3 folders under the / www directory, where 1.html, 2.html and 3.html are stored respectively.
/ www/test1/1.html/www/test2/2.html/www/test3/3.html
Include the additional configuration file httpd-vhosts.conf in httpd.conf, and then write the following configuration in httpd-vhosts.conf:
ServerName www.test1.com DocumentRoot / www/test1/ Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All ServerName www.test1.com DocumentRoot / www/test2/ Options Indexes FollowSymLinks AllowOverride None Order allow Deny Allow From All ServerName www.test1.com DocumentRoot / www/test3/ Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All
It's done. Test each virtual host and access www.test1.com, www.test2.com, and www.test3.com respectively.
Second, based on hostname
Set the domain name to map to the same IP, and 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
As above, set up the root directory where the virtual host stores the web page
/ www/dxGM/index.php/www/dxskadmin/index.php/www/88qp/index.php
Include the additional configuration file httpd-vhosts.conf in httpd.conf, and then write the following configuration in httpd-vhosts.conf:
In order to use a domain name-based virtual host, the server IP address (and possible port) must be specified for the host to accept requests. You can configure it with the NameVirtualHost directive. If all the IP addresses on the server are used, you can use * as the parameter of NameVirtualHost. Specifying the IP address in the NameVirtualHost instruction does not cause the server to automatically listen on that IP address. The IP address set here must correspond to a network interface on the server.
The next step is to set the configuration block for each virtual host you create, and the parameters are the same as those of the NameVirtualHost command. In each definition block, there is at least one ServerName instruction to specify which host to servo and a DocumentRoot instruction to indicate where the contents of the host exist in the file system.
If you add a virtual host to an existing web server, you must also build a definition block for the existing host. The contents of ServerName and DocumentRoot should be consistent with the global content, and should be placed at the front of the configuration file, playing the role of default host.
DocumentRoot "D:/phpstudy/WWW/dxGM" ServerName gm.998gx.com DocumentRoot "D:/phpstudy/WWW/88qp" ServerName www.998gx.com DocumentRoot "D:/phpstudy/WWW/dxskadmin" ServerName r.998gx.com DocumentRoot "D:/phpstudy/WWW" ServerName localhost
Test each virtual host and access gm.998gx.com, www.998gx.com, and r.998gx.com respectively
III. Port-based
Modify the configuration file
Change the original
Listen 80
Change to
Listen 80
Listen 8080
Change the virtual host settings:
DocumentRoot / var/www/test1/ ServerName www.test1.com DocumentRoot / var/www/test2 ServerName www.test2.com above are all the contents of the method of configuring apache virtual host, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.