In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use Apache VirtualHost to build multiple Web sites on a single server. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
development environment
Let me start with my development environment parameters:
OS: RedHat 6.7 (CentOS)
Web Server: Apache 2.2
php5.6.30
Modify Apache configuration
The apache2.2 configuration file path is/etc/httpd/conf/httpd.conf
We modify the apache configuration file with the following command:
$ vim /etc/httpd/conf/httpd.conf
Add listening port
Find the following section,
## Listen: Allows you to bind Apache to specific IP addresses and/or# ports, in addition to the default. See also the # directive.## Change this to Listen on specific IP addresses as shown below to# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)##Listen 12.34.56.78:80Listen 80
By default, it should only listen on port 80, where we add port numbers for other sites. For example, our site A is the default port 80, site B is planned to be built on port 8080, and the final configuration file is modified to
...# Listen 12.34.56.78:80Listen 80Listen 8080
Start and add VirtualHost
Then find the following section in the configuration file:
### Section 3: Virtual Hosts## VirtualHost: 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# # 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 NameVirtualHost *:8080
The above code is what I have modified. By default, the last two lines of NameVirtualHost should also be commented out. Because we want to enable virtual hosting, so here we listen to the two ports are set up.
At the same time, modify the following configuration file to the following way, we first set the default port 80 site A
## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for requests without a known# server name.## ServerAdmin webmaster@dummy-host.example.com DocumentRoot /var/www/webA ServerName webA# ErrorLog logs/dummy-host.example.com-error_log# CustomLog logs/dummy-host.example.com-access_log common
The default Apache is not open VirtualHost, so these codes are commented out, we only need to remove the comments and edit the lines where DocumentRoot and ServerName are located.
DocumentRoot refers to the root directory location of our site A.
Then add the B site information on port 8080.
DocumentRoot /var/www/webB ServerName webB
At this point, restart the Apache service (service httpd restart) and you can access two different sites.
Independent Session
If the login logic of our two sites A and B is a set of codes, then we will find that the sessions of site A and site B are shared, that is, if the user logs in at site A, site B does not need to log in and is automatically logged in; after the user logs out at site A, it will also automatically log out from site B.
This is obviously not the result we want, the reason is that A, B two sites share a set of Session system, so it will cause such problems.
The solution is that we specify the location of the session in the site.
Also modify the configuration file specified virtual host, we take site B as an example, modify the configuration file as follows:
DocumentRoot /var/www/webB ServerName webB AllowOverride All php_value session.save_path "/var/lib/php/session_B"
session.save_path in php_value is actually the session.save_path field in php.ini file. Here, we use the default php.ini configuration file for other values, except for the specified session file storage path. The default php session file is stored in the/var/lib/php/session/folder.
Try visiting the following site B again, and do some session access operations, go back to the/var/lib/php/session_B folder, you will find the new session file.
Thank you for reading! About "how to use Apache VirtualHost to build multiple Web sites in a single server" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!
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.