search
HomeBackend DevelopmentPHP TutorialPHP Beginner: Configure Apache Server and Set Up DNS_PHP Tutorial
PHP Beginner: Configure Apache Server and Set Up DNS_PHP TutorialJul 13, 2016 pm 05:29 PM
apachednsphphostbeginnerItechnologyyesserverpointofparseset upConfiguration

当然主要有技术含量的是点DNS的解析,我正给我们公司负责,先查资料的说...‘

  我们通常所说的虚拟主机技术就是将一台(或者一组)服务器的资源(系统资源、网络带宽、存储空间等)按照一定的比例分割成若干台相对独立的“小主机”的技术。每一台这样的“小主机”在功能上都可以实现WWW、FTP、Mail等基本的Internet服务,就像使用独立的主机一样。
 
    目前网站服务器的虚拟主机平台使用以开放的Apache为最多,其次是微软的Windows IIS。Apache具有跨平台(FreeBSD/Linux/Windows/Solaris/Other UNIX)、易于维护与最佳安全性等优点。
    Apache是率先支持基于IP虚拟主机的服务器之一。 Apache 1.1及其更新版本同时支持基于IP和基于主机名的虚拟主机,不同的虚拟主机有时会被称为基于主机(host-based) 或非IP虚拟主机(non-IP virtual hosts)。

    用Apache设置虚拟主机服务通常可以采用两种方案:基于IP地址的虚拟主机和基于主机名字的虚拟主机,下面我们分别介绍一下它们的实现方法以及优缺点。以便大家在具体的应用中能够选择最合适的实现方法。

   一、Apache实现基于IP地址的虚拟主机(每个站点拥有一个独立IP地址)

    使用这种虚拟主机方式,首先要在服务器上为每个虚拟主机单独设置一个IP地址。这些IP地址可以通过增加多个网卡或者在一个网卡上设立多个IP地址来完成。有了多个IP地址后,可以采用以下两种方式之一来设置Apache。

1、为每个虚拟主机运行一份Apache
    采用这种方式,每一份Apache程序可以以单独的用户运行,因此各个虚拟主机之间互不影响。设置这种虚拟主机时,只要为每一份Apache设置一套配置文件就可以了,唯一需要注意的是:必须使用“Listen”语句,强制每一份Apache 仅仅在属于“自己”的IP地址上接收服务请求。

    优点:各个虚拟主机之间互不干扰,安全性高。
    缺点:占用系统资源较多。

2、多个虚拟主机共享同一份Apache
    采用这种方式,各个虚拟主机共享同一份Apache,因此各个虚拟主机之间有一定的影响,尤其是执行CGI程序时,可能会带来一些严重的安全问题。设置这种虚拟主机时,只要为每一个虚拟主机设置类似如下的信息即可:
   
    DocumentRoot /www/ghq1
    …
   

    优点:占用系统资源比上一种方式少。
    缺点:安全性低,每个虚拟主机仍然需要占用一个IP地址。

  
    例如服务器一个网卡上绑定有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org的服务,配置如下:

    服务器配置(apache的配置文件httpd.conf)
    Listen 80

   
    DocumentRoot /www/ghq1
    ServerName www.ghq1.com
   

   
    DocumentRoot /www/ghq2
    ServerName www.ghq2.org
   

    配置简单说明:“Listen”默认httpd服务会监控第80号通信端口, “Listen”选项让用户自行指定apache 服务器监控的IP地址或通信端口。

    “DocumentRoot”:指定apache 服务器存放网页的根目录;“ServerName”:允许用户自行设置主机名,这个名称将被送到远程连接程序,以取代安装apache 服务器主机的真实名称。构成虚拟主机的语法结构,其中的IP就是我们在服务器上绑定的不同的IP地址,也可以是IP地址加上通信端口号(见下面的例子)。

    如果服务器有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org。对每个域名,我们都希望在80端口和8080端口发布我们的网站。可以这样配置:

Server configuration (apache configuration file httpd.conf)
Listen 172.16.3.40:80
Listen 172.16.3.40:8080
Listen 172.16.3.50:80
Listen 172.16.3.50: 8080


DocumentRoot /www/ghq1-80
ServerName www.ghq1.com


DocumentRoot /www/ghq1-8080
ServerName www.ghq1.com


DocumentRoot /www/ghq2-80
ServerName www.ghq1.org


  DocumentRoot /www/ghq2-8080
  ServerName www.ghq2.org

Therefore, to establish a virtual host, we need to do domain name resolution work corresponding to different IPs, establish a corresponding directory (such as /www/ghq1), and store the corresponding homepage content in the corresponding directory.

2. Apache implements a virtual host service based on the host name (one IP address implements multiple websites)

The virtual host service based on the host name is a commonly used solution for virtual hosts at present. Because it does not require more IP addresses and no special software or hardware support. And most of today's browsers support this virtual host implementation method. Domain name-based virtual hosts are determined based on the hostname part of the HTTP header submitted by the client. Using this technology, many virtual hosts can share the same IP address.

Domain name-based virtual hosting is relatively simple, because we only need to configure the DNS server to map each host name (CNAMES) to the correct IP address, and then configure the Apache HTTP server to recognize different host names. . Domain name-based servers can also alleviate the problem of insufficient IP addresses (IPV4). In this way, each virtual host shares the same Apache, so when a CGI program is running, the security is not high.

Advantages: Only one IP address can provide a large number of virtual host services.
Disadvantages: Poor security. Maintaining these virtual hosts requires configuration file changes, and the Apache process needs to be restarted for it to work. Therefore, it is not suitable for large-scale virtual hosting services.

If the server has only one IP address and there are many mapped to this machine in DNS. We want to run two sites www.ghq1.com and www.ghq2.org on this machine. Creating a virtual host in the Apache server configuration does not automatically update the hostname in DNS accordingly. We have to add the domain name in DNS ourselves to point to our IP address. Otherwise others will not be able to see our web site.

Server configuration (apache configuration file httpd.conf)
# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *


DocumentRoot /www/ghq1
ServerName www.ghq1.com

# Other directives here


DocumentRoot /www/ghq2
ServerName www.ghq2.org

# Other directives here

Because * (asterisk) matches all addresses, the main server does not accept any requests. Because www.ghq1.com appears first in the configuration file, it has the highest priority and can be considered the default or primary server. This means that if an accepted request does not match a ServerName directive, it will be served by the first VirtualHost.

When our IP address cannot be determined, it is very convenient to use * - for example, the ISP has configured us with a dynamic IP address (such as ADSL dial-up Internet access), and we have used some kind of dynamic domain name resolution system time. Because * matches any IP address, in this case, no matter how the IP address changes, we do not need to configure it separately. The above configuration is that we use domain name-based virtual hosts in most cases

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/509201.htmlTechArticleOf course, the main technical content is the resolution of DNS. I am responsible for our company, so I will check the information first. ...' What we usually call virtual host technology is to combine one (or a group of) services...
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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),