From: Ryan Bloom All.
Port
- 80Number is a number from 0 to 65535; some port
- numbers (especially below 1024) are reserved for particular
- protocols. See /etc/services for a list of some
- defined ports; the standard port for the http protocol is
- 80.
The Port directive has two behaviors, the first of which is - necessary for NCSA backwards compatibility (and which is - confusing in the context of Apache).
- -:number then Port
- has no effect on what address the server listens at.SERVER_PORT
- environment variable (for CGI and
- SSI), and is used when the
- server must generate a URL that refers to itself (for example
- when creating an external redirect to itself). This behaviour
- is modified by UseCanonicalName.Port 80 is one of Unix's special ports. All ports numbered - below 1024 are reserved for system use, i.e., regular - (non-root) users cannot make use of them; instead they can only - use higher port numbers. To use port 80, you must start the - server from the root account. After binding to the port and - before accepting requests, Apache will change to a low - privileged user as set by the User directive.
- -If you cannot use port 80, choose any other unused port. - Non-root users will have to choose a port number higher than - 1023, such as 8000.
- -SECURITY: if you do start the server as root, be sure not to - set User to root. If you run - the server as root whilst handling connections, your site may - be open to a major security attack.
--would be used if the canonical (main) name of the actual machine wereServerName www.example.com+ServerName www.example.com:80
simple.example.com.
@@ -2300,6 +2232,12 @@
section specifies what hostname must appear in the request's
Host: header to match this virtual host.
+ This directive now takes allows a port to be added to the + server name. This allows an admin to assign the canonical + port at the same time that the canonical name is assigned. + The Port directive, which used to perform this role, has also + been removed, easing configuration for all users. +
See Also: The Listen directive instructs Apache to listen to only
specific IP addresses or ports; by default it responds to
- requests on all IP interfaces, but only on the port given by
- the The Listen directive tells the server to accept incoming
requests on the specified port or address-and-port combination.
diff --git a/server/core.c b/server/core.c
index c15bb173959..7bbe1d744e9 100644
--- a/server/core.c
+++ b/server/core.c
@@ -1603,15 +1603,27 @@ static const char *set_server_string_slot(cmd_parms *cmd, void *dummy,
return NULL;
}
-static const char *server_port(cmd_parms *cmd, void *dummy, const char *arg)
+static const char *server_hostname_port(cmd_parms *cmd, void *dummy, const char *arg)
{
const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
+ const char *portstr;
+ const char *server;
int port;
if (err != NULL) {
return err;
}
- port = atoi(arg);
+ portstr = ap_strchr_c(arg, ':');
+ if (portstr) {
+ cmd->server->server_hostname = apr_pstrndup(cmd->pool, arg,
+ portstr - arg);
+ portstr++;
+ port = atoi(portstr);
+ }
+ else {
+ cmd->server->server_hostname = apr_pstrdup(cmd->pool, arg);
+ port = 80;
+ }
if (port <= 0 || port >= 65536) { /* 65536 == 1<<16 */
return apr_pstrcat(cmd->temp_pool, "The port number \"", arg,
"\" is outside the appropriate range "
@@ -2411,7 +2423,8 @@ AP_INIT_TAKE1("DefaultType", ap_set_string_slot,
/* Old server config file commands */
-AP_INIT_TAKE1("Port", server_port, NULL, RSRC_CONF, "A TCP port number"),
+AP_INIT_TAKE1("Port", ap_set_deprecated, NULL, RSRC_CONF,
+ "Port was replaced with Listen in Apache 2.0"),
AP_INIT_TAKE1("HostnameLookups", set_hostname_lookups, NULL,
ACCESS_CONF|RSRC_CONF,
"\"on\" to enable, \"off\" to disable reverse DNS lookups, or \"double\" to "
@@ -2419,9 +2432,8 @@ AP_INIT_TAKE1("HostnameLookups", set_hostname_lookups, NULL,
AP_INIT_TAKE1("ServerAdmin", set_server_string_slot,
(void *)APR_XtOffsetOf (server_rec, server_admin), RSRC_CONF,
"The email address of the server administrator"),
-AP_INIT_TAKE1("ServerName", set_server_string_slot,
- (void *)APR_XtOffsetOf (server_rec, server_hostname), RSRC_CONF,
- "The hostname of the server"),
+AP_INIT_TAKE1("ServerName", server_hostname_port, NULL, RSRC_CONF,
+ "The hostname and port of the server"),
AP_INIT_TAKE1("ServerSignature", set_signature_flag, NULL, OR_ALL,
"En-/disable server signature (on|off|email)"),
AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF,
diff --git a/server/listen.c b/server/listen.c
index 8225efc9e97..8068dce659e 100644
--- a/server/listen.c
+++ b/server/listen.c
@@ -273,11 +273,10 @@ int ap_listen_open(process_rec *process, apr_port_t port)
ap_listen_rec *next;
int num_open;
- /* allocate a default listener if necessary */
- if (ap_listeners == NULL) {
- alloc_listener(process, NULL, (apr_port_t)(port ? port : DEFAULT_HTTP_PORT));
- }
-
+ /* Don't allocate a default listener. If we need to listen to a
+ * port, then the user needs to have a Listen directive in their
+ * config file.
+ */
num_open = 0;
for (lr = ap_listeners; lr; lr = lr->next) {
if (lr->active) {
DNS Issues
Apache virtual host
diff --git a/docs/manual/mod/mpm_common.html b/docs/manual/mod/mpm_common.html
index bc414cee85b..c9465501454 100644
--- a/docs/manual/mod/mpm_common.html
+++ b/docs/manual/mod/mpm_common.html
@@ -208,9 +208,10 @@
Port
- directive.