diff --git a/src/nhttpd/yconfig.h b/src/nhttpd/yconfig.h index 47808a318..8951987e2 100644 --- a/src/nhttpd/yconfig.h +++ b/src/nhttpd/yconfig.h @@ -88,6 +88,7 @@ #undef HTTPD_NAME #define HTTPD_NAME "nhttpd" #define HTTPD_STANDARD_PORT 80 +#define HTTPD_FALLBACK_PORT 8080 #define HTTPD_MAX_CONNECTIONS 50 #define HTTPD_REQUEST_LOG "/tmp/httpd_log" #define SSL_PEMFILE HTTPD_CONFIGDIR "/server.pem" diff --git a/src/nhttpd/yhttpd_core/ywebserver.cpp b/src/nhttpd/yhttpd_core/ywebserver.cpp index e3debef47..8f664465c 100644 --- a/src/nhttpd/yhttpd_core/ywebserver.cpp +++ b/src/nhttpd/yhttpd_core/ywebserver.cpp @@ -51,7 +51,7 @@ CWebserver::CWebserver() { pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); #endif - port = 80; + port = HTTPD_STANDARD_PORT; } //----------------------------------------------------------------------------- @@ -118,14 +118,15 @@ CWebserver::~CWebserver() { bool CWebserver::run(void) { set_threadname("ywebsrv::run"); if (!listenSocket.listen(port, HTTPD_MAX_CONNECTIONS)) { - if (port != 80) { - fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d Abort.\n", port); + if (port != HTTPD_STANDARD_PORT) { + // WebsiteMain.port in nhttpd.conf is changed by user + fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d. Abort.\n", port); return false; } - fprintf(stderr, "[yhttpd] cannot bind and listen on port 80, retrying on port 8080.\n"); - port = 8080; + fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d. Retrying port %d.\n", HTTPD_STANDARD_PORT, HTTPD_FALLBACK_PORT); + port = HTTPD_FALLBACK_PORT; if (!listenSocket.listen(port, HTTPD_MAX_CONNECTIONS)) { - fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d Abort.\n", port); + fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d. Abort.\n", HTTPD_FALLBACK_PORT); return false; } }