Home  >  Article  >  Backend Development  >  Apache set up virtual WEB_PHP tutorial

Apache set up virtual WEB_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:08:351025browse


Apache Server sets up virtual WEB

Let’s give an example first:
Suppose your PHP is installed under d:/php/.
Copy php4apache.dll (php4apache2.dll) to d:/php/
Add below Aapche’s httpd.conf:

############################### #####################
Aapche1 is:
LoadModule php4_module "d:/php/php4apache.dll"
Aapche2 is:
LoadModule php4_module "d:/php/php4apache2.dll"

Add extension parsed by PHP:
AddType application/x-httpd-php .phtml .pwml .php3 .php4 .php . php2 .inc .izz
######################################### ############

Now, you only need to restart Apache to support PHP.

#The following line is only supported by Apache1
LoadModule gzip_module modules/ApacheModuleGzip.dll



ApacheModuleGzip (ie: mod_gzip) is an Apache module provided for free by Remote Communications, which can compress static web pages. It works just fine, you just need to compile it with apache (or use it as a DSO).

You can also download it from Bingbing’s website:
http://justdn.com/down/apache/ApacheModuleGzip.dll

More PHP acceleration and buffering suggestions can be found at Bingbing Get it from the PHP document.

How does Apache build a virtual host? The following is a brief introduction to virtual hosts based on domain names.
For example, your server address is: 61.132.27.69 (this is Bingbing), now We want to build two virtual hosts www.justdn.org and www.justdn.com.
Add the following code after Apache’s httpd.conf

########## ###########################################
NameVirtualHost 61.132. 27.69

ServerAdmin webmaster@justdn.com
DocumentRoot C:/home/justdn.com/
ServerName www.justdn.com
ServerAlias ​​justdn.com wwww.justdn.com
ErrorLog logs/www.justdn.com-error_log
CustomLog logs/www.justdn.com-access_log common
ErrorDocument 404 /404.html


ServerAdmin webmaster@justdn.com
DocumentRoot c:/home/justdn.org/
ServerName www.justdn.org
ServerAlias ​​wwww.justdn.org justdn.org
ErrorLog logs/www.justdn.org-error_log
CustomLog logs/www.justdn.org-access_log common

######### ###########################################

Explanation below,
ServerAdmin, is the administrator’s email.
DocumentRoot, the site document directory of the virtual host.
ServerName, the domain name.
ServerAlias ​​justdn.com wwww.justdn.com , indicating that you can use www.justdn.com to access the site, and you can also use justdn.com to access the site.
ErrorDocument 404 /404.html, which refers to customizing the 404 page of the site as the 404.html file in the root directory of the site .



Note:
Unix platform and NT platform use the same apache server settings. The following focuses on the unix platform as an example to illustrate the settings of apache server. It is also worth noting that for the successful setup of a virtual web, about 50% of the workload is in the registration and resolution of domain names. Therefore, generally register the domain name first and then do the virtual WEB settings.

1. IP-type virtual host
IP-type virtual host means that each virtual host corresponds to a unique IP. Multiple IPs can be achieved through multiple physical network cards or virtual network ports. Both Solaris2.5 and Windows NT support this method.
Two methods to configure multiple virtual hosts:
1. Start an httpd process for each virtual host.
Use this method under the following circumstances:
1) Security isolation issues need to be considered. For example, two httpds run on different User, Group, Listen, and ServerRoot. Users of the two cannot access other data except browsing each other's data through the Web. data.
2) Can provide sufficient memory and file descriptors.
Setting method:
Create an independent httpd installation for each virtual host. In the configuration file httpd.conf of each installation path, use the Listen command to specify the IP of the process service, such as: Listen 10.68.37.10: 80
2. Start an httpd process for all virtual hosts.
Use this method in the following situations:
1) Allow sharing httpd configuration between virtual hosts.
2) The computer serves a large number of requests, and running multiple processes reduces server performance and becomes an important consideration.
Setting method:
In the configuration file httpd.conf, use the VirtualHost command to set ServerAdmin, ServerName, DocumentRoot, ErrorLog, TransferLog or CustomLog for each virtual host, such as:
〈VirtualHost www.smallco.com 〉 #It is recommended to use IP here
ServerAdmin webmaster@mail.smallco.com
DocumentRoot /usr/local/etc/httpd/htdocs/smallco
ServerName www.smallco.com #It is recommended to use domain name here
ErrorLog /usr/local/etc/httpd/logs/smallco/error_log
TransferLog /usr/local/etc/httpd/logs/smallco/access_log
〈/VirtualHost〉
〈VirtualHost www.baygroup .org〉 #It is recommended to use IP here
ServerAdmin webmaster@mail.baygroup.org
DocumentRoot /groups/baygroup/www
ServerName www.baygroup.org #It is recommended to use domain name here
ErrorLog / groups/baygroup/logs/error_log
TransferLog /groups/baygroup/logs/access_log
〈/VirtualHost〉
At the same time, you need to configure the virtual network port or network card, and you need to make corresponding settings in DNS.
2. Name-based virtual host (supported by Apache 1.3 or above)
Although IP-based virtual host is good, it is not the best solution. It requires each virtual host to have a dedicated IP, which is difficult to implement on some machines. Name-type virtual host means that each virtual host has a different name but the same IP. Its advantage is that it does not limit the number of virtual hosts, is simple to configure and use, and does not require additional software or hardware. The disadvantage is that the client must support this part of the protocol. Recent versions of browsers support it, but some older versions of browsers do not. But Apache provides a workaround for this.
Setting method:
In the configuration file httpd.conf, use the NameVirtualHost command to set the virtual host, such as:
NameVirtualHost 111.22.33.44
〈VirtualHost 111.22.33.44〉 #It is recommended to use IP here
ServerName www.domain.tld #It is recommended to use the domain name here
DocumentRoot /web/domain
〈/VirtualHost>
At the same time, define www.domain.tld in DNS to point to 111.22.33.44.
Note: When using IP after the NameVirtualHost directive, any URL request using IP is for the virtual host, and the main server will never respond to a URL request using IP. Additionally, some servers wish to be accessed under multiple names. For example, suppose there is a server with a certain IP and you want to be able to access it with the names domain.tld and www2.domain.tld. The method is to use the ServerAlias ​​directive in the VirtualHost directive section. For example: ServerAlias ​​domain.tld *.domain.tld
Attached are some virtual host setting examples.


Attachment: Virtual host setup example
IP type virtual host configuration
Setup 1: The server has two IPs,
111.22.33.44 server.domain.tld
111.22.33.55 www.otherdomain.tld
www.domain.tld is the alias (CNAME) of server.domain.tld, which represents the main server.
Server configuration:
...
Port 80
DocumentRoot /www/domain
ServerName www.domain.tld
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/ otherdomain
ServerName www.otherdomain.tld
...
〈/VirtualHost〉
Setup 2: Basically the same as Setup1, but without setting up a dedicated main server.
Server configuration:
...
Port 80
ServerName server.domain.tld
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/domain
ServerName www.domain .tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/otherdomain
ServerName www.otherdomain.tld
...
〈/VirtualHost〉
This setting only hits the main server when the URL is http://server.domain.tld
Setup 3: The server has two IPs,
111.22.33.44 server.domain .tld
111.22.33.55 www-cache.domain.tld
www.domain.tld is the alias (CNAME) of server.domain.tld and represents the main server.
www-cache.domain.tld is proxy-cache, the port is 8080, and the web server uses the default 80.
Server configuration:
...
Port 80
Listen 111.22.33.44:80
Listen 111.22.33.55:8080
ServerName server.domain.tld
〈VirtualHost 111.22 .33.44:80〉
DocumentRoot /www/domain
ServerName www.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55:8080〉
ServerName www-cache.domain.tld
...
〈Directory proxy:〉
order deny,allow
deny from all
allow from 111.22.33
〈/Directory〉
〈/VirtualHost〉

Named virtual host configuration
Setup 1: The server has an IP,
111.22.33.44 server.domain.tld.
www.domain.tld and www .sub.domain.tld is an alias (CNAMEs).
Server configuration:
...
Port 80
ServerName server.domain.tld
NameVirtualHost 111.22.33.44
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/domain
ServerName www.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/subdomain
ServerName www.sub.domain.tld
...
〈/VirtualHost>
If you use IP to access the server, since www.domain.tld has the highest priority, it is considered to be the default server or
the first server.
Setup 2: The server has two IPs,
111.22.33.44 server1.domain.tld is used for the main server
111.22.33.55 server2.domain.tld is used for the virtual host
alias www.domain. tld is used for the main server,
alias www.otherdomain.tld is used for one virtual host,
alias www.sub.domain.tld, *.sub.domain.tld is used for another virtual host,
Server configuration:
...
Port 80
ServerName www.domain.tld
DocumentRoot /www/domain
NameVirtualHost 111.22.33.55
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/otherdomain
ServerName www.otherdomain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/subdomain
ServerName www. sub.domain.tld
ServerAlias ​​*.sub.domain.tld
...
〈/VirtualHost〉
Mixed (IP/name) virtual host configuration
Setup: There are three servers IP,
111.22.33.44 server.domain.tld is used for name-type virtual host
111.22.33.55 www.otherdomain1.tld is used for IP-type virtual host
111.22.33.66 www.otherdomain2.tld is used for IP Type virtual host
Server configuration:
...
Port 80
ServerName server.domain.tld
NameVirtualHost 111.22.33.44
〈VirtualHost 111.22.33.44〉
DocumentRoot / www/domain
ServerName www.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/subdomain1
ServerName www.sub1. domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.44〉
DocumentRoot /www/subdomain2
ServerName www.sub2.domain.tld
...
〈/VirtualHost〉
〈VirtualHost 111.22.33.55〉
DocumentRoot /www/otherdomain1
ServerName www.otherdomain1.tld
...
〈/VirtualHost〉
〈 VirtualHost 111.22.33.66〉
DocumentRoot /www/otherdomain2
ServerName www.otherdomain2.tld
...
〈/VirtualHost〉
Port type virtual host configuration
Setup: The server has An IP,
111.22.33.44 www.domain.tld
does not require another alias or IP. Using a port-type virtual host, you can set up a virtual
virtual host with a configuration different from the main server.
Server configuration:
...
Listen 80
Listen 8080
ServerName www.domain.tld
DocumentRoot /www/domain
〈VirtualHost 111.22.33.44:8080〉
DocumentRoot /www/domain2
...
〈/VirtualHost>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314749.htmlTechArticleApacheServer sets up a virtual WEB. Let’s give an example first: Assume that your PHP is installed under d:/php/. Copyphp4apache. dll (php4apache2.dll) to d:/php/ Add below Aapche’s httpd.conf: ###################...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn