翻译 - Building to Addresses and Ports

http://httpd.apache.org/docs/2.4/bind.html

Binding to Addresses and Ports

Configuring Apache HTTP Server to listen on specific addresses and ports.

配置Apache的HTTP服务器,使它监听指定的地址和端口。

Overview 预览

Related Modules

Related Directive

core <VirtualHost>
mpm_common Listen

 

 

 

When httpd starts, it binds to some port and address on the local machine and waits for incoming requests.

当httpd启动时,它会监听本机器的端口和地址并等待请求。

By default, it listens to all addresses on the machine.

默认的服务是监听本机器所有的(IP)地址的。

Howeveer, it may need to be told to listen on specific ports, or only on selected address, or a combination of both.

然而,也可能被指定要监听指定的端口,或选择的地址,或者前两者(端口与地址)的组合。

This is often combined with the Virtual Host feature, which determines how httpd responds to different IP addresses, hostnames and ports.

经常结合使用虚拟主机功能,决定httpd在不同的IP地址,主机名与端口间如何做出响应。

The Listen directive tells the server to accept incoming requests only on the specific port(s) or address-and-port combinations.

Listen指令告诉服务器只在指定的端口或地址与端口的组合接收请求。

If only a port number is specificed in the Listen directive, the server listens to the given port on all interfaces. 

如果在Listen指令中只给指定一个端口号,那么服务器在所有的接口只监听给定的端口。

If an IP address is given as well as a port, the server will listen on the given port and interface.

如果一个IP像端口一样给定,那么服务器只监听给定的端口和接口(接口这个东西就简单粗暴的理解为IP好了)。

Multiple Listen directvies may be used to specify a number of addresses and ports to listen on.

多个Listen指令可以用来指定一系列地址和端口来给服务器监听。

For example, to make the server accept connections on both port 80 and port 8000, on all interfaces, use:

例如,为在所有的接口上,让服务器在80和8000端口接收链接,可以如下设置:

Listen 80
Listen 8000

 

To make the server accept connections on port 80 for one interface, and port 8000 on an another, use:

为在一个接口上监听80端口,在另一个接口上监听8000端口,设置如下:

Listen 192.0.2.1:80
Listen 192.0.2.5:8000

 

IPv6 addresses must be enclosed in square brackets, as in the following example:

IPv6地址必须用中括号包住,像下面这样:

Listen [2001:db8:a00:20ff:fea7:ccea]:80

 


Overlapping Listen directive will result in a fatal error which will prevent the server from starting up.

重载Listen指令在服务器启动时将引发致命错误。

(48)Address already in use: make_sock: could not bind to address [::]:80

See the discussion in the wiki for further troubleshooting tips.

查看wiki的讨论区,寻找问题的深入解决方案。

 

Special IPv6 Considerations IPv6特定的注意事项

A growing number of platforms implement IPv6, and APR supports IPv6 on most of these platforms, allowing httpd to allocate IPv6 sockets, and to handle requests sent over IPv6.

支持IPv6的平台越来越多,允许httpd分配IPv6的sockets并且通过发送IPv6处理请求。(不通顺)

One complicating factor for httpd administrator is whether or not an IPv6 socket can handle both IPv4 connections and IPv6 connections.

对于httpd管理员一个复杂的因素是一个IPv6的scoket能否同时处理IPv4和IPv6的连接。

Handling IPv4 connetions with an IPv6 socket uses IPv4-mapped IPv6 addresses, which are allowed by default on most platforms, but are disallowed by default on FreeBSD, NetBSD, and OpenBSD, in order to match the system-wide policy on those platforms.

通过IPv4映射的IPv6地址,使用IPv6的socket处理IPv4的连接,这在大多数平台上默认是允许的,但是为系统方面的考虑,有些平台不支持这样,如FreeBSD,NetBSD,OpenBSD等。

On systems where it is disallowed by default, a special configure parameter can change this behavior for httpd.

在默认不允许的系统上,一个特定的配置参数可以为httpd改变这个行为。

On the other hand, on some platforms, such as Linux and Tru64, the only way to handle both IPv6 and IPv4 is to use mapped addresses.

另一个方面,在一些平台上,如Linux和Tru64,同时处理IPv4和IPv6的位置方法就是通过映射的地址。

If you want httpd to handle IPv4 and IPv6 connections with a minimum of sockets, which requires using IPv4-mapped IPv6 address, specify the --enbale-v4-mapped configure option.

如果你想要httpd使用最少的sockets来处理IPv4和IPv6的连接,需要使用IPv4映射IPv6地址,指定的配置项为 --enbale-v4-mapped。

--enbale-v4-mapped is the default on all platforms except FreeBSD, NetBSD, and OpenBSD, so this is probably how your httpd was built.

--enable-v4-mapped在除FreeBSD, NetBSD和OpenBSD外的平台上默认是开启的,所以这就是大概如何构建你的httpd。

If you want httpd to handle IPv4 connecitons only, regardless of what your platform and APR will support, specify an IPv4 address on all Listen directives, as in the following examples:

如果你想只处理IPv4的连接,不管你什么平台或APR是否支持,在Listen指令中指定一个IPv4地址,像下面这样:

Listen 0.0.0.0:80
Listen 192.0.2.1:80

If your platform support it and you want httpd to handle IPv4 and IPv6 connections on separate sockets(i.e.,to disable IPv4-mapped addresses),specify the --disable-v4-mapped configure option.

如果你的系统支持,且你想httpd分别处理IPv4和IPv6连接(例如:禁用IPv4映射IPv6地址),可以指定配置项:--disable-v4-mapped。

Specifying the protocol with Listen 使用Listen指令指定协议

The optional second protocol argument of Listen is not required for most configurations.

Listen的第二个配置参数很多时候不是必须的。

If not specified, https is the default for port 443 and http the default for all other ports.

如果不指定,https默认的是443端口,http默认的为其他端口。

The protocol is used to determine which module should handle a request, and to apply protocol specific optimizations with the AcceptFilter directive.

协议决定哪个模块来处理请求,且应用协议特殊优化,使用AcceptFilter指令。

You only need to set the protocol if you are running on non-standard ports.For example, running an https site on port 8443:

当你在非标准端口运行的时候需要指定协议,如在8443端口运行一个https站点:

Listen 192.170.2.1:8443 https

 

How This Works With Virtual Hosts 虚拟主机是如何工作的

The Listen directive does not implement Virtual Hosts - it only tells the main server what address and ports to listen on.

Listen指令没有实现虚拟主机,它只是告诉主服务监听的地址和端口。

If no <VirtualHost> directives are used, the server will behave in the same way for all accepted requests.

如果没有使用VirtualHost指令,服务将会退所有接收的请求给予相同的表现。

However, <VirtualHost> can be used to specify a different behavior for one or more of the addresses or ports.

然后,VirtualHost可以为不同的地址或端口指定不同的行为。

To implement a VirtualHost, the server must first be told to listen to the address and port to be used.

为了实现虚拟主机,服务器必须首页被告知要监听的地址或端口。

The a <VirutalHost> section should be created for the sepcified address and port to set the behavior of this virtual host.

为指定的地址和端口设置虚拟主机,VirtualHost片段需要先创建。

Note that if the <VirtualHost> is set for an address and port that the server is not listening to, it cannot be accessed.

如果虚拟主机设置的地址和端口没有被监听,是不会通过的。

 

posted on 2014-08-29 14:57  古道倦马  阅读(404)  评论(0编辑  收藏  举报

导航