2012-06-04 16:48:31 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-06-04 16:48:31 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "shrpx.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
2012-08-01 17:06:41 +02:00
|
|
|
#include <sys/stat.h>
|
2012-06-04 16:48:31 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <signal.h>
|
2012-06-06 15:43:35 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2012-06-06 16:58:19 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
2012-08-01 18:20:18 +02:00
|
|
|
#include <syslog.h>
|
2014-07-05 11:22:40 +02:00
|
|
|
#include <signal.h>
|
2014-08-12 15:22:02 +02:00
|
|
|
#include <limits.h>
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2012-06-06 16:58:19 +02:00
|
|
|
#include <limits>
|
2012-06-04 16:48:31 +02:00
|
|
|
#include <cstdlib>
|
2012-06-06 16:58:19 +02:00
|
|
|
#include <iostream>
|
2012-07-31 18:51:16 +02:00
|
|
|
#include <fstream>
|
2012-08-01 17:06:41 +02:00
|
|
|
#include <vector>
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
2014-08-02 03:11:45 +02:00
|
|
|
#include <openssl/conf.h>
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
#include <event2/listener.h>
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.h>
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
#include "shrpx_config.h"
|
|
|
|
#include "shrpx_listen_handler.h"
|
2012-06-08 15:41:24 +02:00
|
|
|
#include "shrpx_ssl.h"
|
2014-07-05 11:22:40 +02:00
|
|
|
#include "shrpx_worker_config.h"
|
2014-08-12 15:22:02 +02:00
|
|
|
#include "shrpx_worker.h"
|
2014-01-08 17:27:56 +01:00
|
|
|
#include "util.h"
|
2014-02-09 10:47:26 +01:00
|
|
|
#include "app_helper.h"
|
2014-03-04 13:33:43 +01:00
|
|
|
#include "ssl.h"
|
2014-01-08 17:27:56 +01:00
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
extern char **environ;
|
|
|
|
|
2014-01-08 17:27:56 +01:00
|
|
|
using namespace nghttp2;
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
namespace shrpx {
|
|
|
|
|
2014-07-05 11:22:40 +02:00
|
|
|
namespace {
|
|
|
|
const int REOPEN_LOG_SIGNAL = SIGUSR1;
|
2014-08-12 15:22:02 +02:00
|
|
|
const int EXEC_BINARY_SIGNAL = SIGUSR2;
|
|
|
|
const int GRACEFUL_SHUTDOWN_SIGNAL = SIGQUIT;
|
2014-07-05 11:22:40 +02:00
|
|
|
} // namespace
|
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
// Environment variables to tell new binary the listening socket's
|
|
|
|
// file descriptors. They are not close-on-exec.
|
|
|
|
#define ENV_LISTENER4_FD "NGHTTPX_LISTENER4_FD"
|
|
|
|
#define ENV_LISTENER6_FD "NGHTTPX_LISTENER6_FD"
|
|
|
|
|
|
|
|
// Environment variable to tell new binary the port number the current
|
|
|
|
// binary is listening to.
|
|
|
|
#define ENV_PORT "NGHTTPX_PORT"
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace {
|
|
|
|
void ssl_acceptcb(evconnlistener *listener, int fd,
|
|
|
|
sockaddr *addr, int addrlen, void *arg)
|
|
|
|
{
|
2014-01-19 11:46:58 +01:00
|
|
|
auto handler = static_cast<ListenHandler*>(arg);
|
2012-06-04 16:48:31 +02:00
|
|
|
handler->accept_connection(fd, addr, addrlen);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-06-14 16:01:47 +02:00
|
|
|
namespace {
|
|
|
|
bool is_ipv6_numeric_addr(const char *host)
|
|
|
|
{
|
|
|
|
uint8_t dst[16];
|
|
|
|
return inet_pton(AF_INET6, host, dst) == 1;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace {
|
2013-02-09 08:42:01 +01:00
|
|
|
int resolve_hostname(sockaddr_union *addr, size_t *addrlen,
|
|
|
|
const char *hostname, uint16_t port, int family)
|
2012-06-04 16:48:31 +02:00
|
|
|
{
|
|
|
|
addrinfo hints;
|
|
|
|
int rv;
|
2012-06-06 16:58:19 +02:00
|
|
|
|
2014-05-14 15:39:28 +02:00
|
|
|
auto service = util::utos(port);
|
2012-06-04 16:48:31 +02:00
|
|
|
memset(&hints, 0, sizeof(addrinfo));
|
2012-06-06 16:58:19 +02:00
|
|
|
|
2013-02-09 08:42:01 +01:00
|
|
|
hints.ai_family = family;
|
2012-06-04 16:48:31 +02:00
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
#ifdef AI_ADDRCONFIG
|
|
|
|
hints.ai_flags |= AI_ADDRCONFIG;
|
|
|
|
#endif // AI_ADDRCONFIG
|
2012-06-05 18:26:04 +02:00
|
|
|
addrinfo *res;
|
2012-06-06 16:58:19 +02:00
|
|
|
|
2014-05-14 15:39:28 +02:00
|
|
|
rv = getaddrinfo(hostname, service.c_str(), &hints, &res);
|
2012-06-04 16:48:31 +02:00
|
|
|
if(rv != 0) {
|
2013-02-09 08:42:01 +01:00
|
|
|
LOG(FATAL) << "Unable to resolve address for " << hostname
|
|
|
|
<< ": " << gai_strerror(rv);
|
|
|
|
return -1;
|
2012-06-05 18:26:04 +02:00
|
|
|
}
|
2012-06-06 15:43:35 +02:00
|
|
|
|
|
|
|
char host[NI_MAXHOST];
|
|
|
|
rv = getnameinfo(res->ai_addr, res->ai_addrlen, host, sizeof(host),
|
|
|
|
0, 0, NI_NUMERICHOST);
|
2014-07-17 17:21:15 +02:00
|
|
|
if(rv != 0) {
|
2013-02-09 08:42:01 +01:00
|
|
|
LOG(FATAL) << "Address resolution for " << hostname << " failed: "
|
|
|
|
<< gai_strerror(rv);
|
2014-07-17 17:21:15 +02:00
|
|
|
|
|
|
|
freeaddrinfo(res);
|
|
|
|
|
2013-02-09 08:42:01 +01:00
|
|
|
return -1;
|
2012-06-06 15:43:35 +02:00
|
|
|
}
|
2014-07-17 17:21:15 +02:00
|
|
|
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Address resolution for " << hostname << " succeeded: "
|
|
|
|
<< host;
|
|
|
|
}
|
|
|
|
|
2013-02-09 08:42:01 +01:00
|
|
|
memcpy(addr, res->ai_addr, res->ai_addrlen);
|
|
|
|
*addrlen = res->ai_addrlen;
|
2012-06-04 16:48:31 +02:00
|
|
|
freeaddrinfo(res);
|
2012-06-05 18:26:04 +02:00
|
|
|
return 0;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-06-05 19:23:07 +02:00
|
|
|
namespace {
|
|
|
|
void evlistener_errorcb(evconnlistener *listener, void *ptr)
|
|
|
|
{
|
2012-06-06 14:44:08 +02:00
|
|
|
LOG(ERROR) << "Accepting incoming connection failed";
|
2012-06-05 19:23:07 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
namespace {
|
|
|
|
evconnlistener* new_evlistener(ListenHandler *handler, int fd)
|
|
|
|
{
|
|
|
|
auto evlistener = evconnlistener_new
|
|
|
|
(handler->get_evbase(),
|
|
|
|
ssl_acceptcb,
|
|
|
|
handler,
|
|
|
|
LEV_OPT_REUSEABLE | LEV_OPT_CLOSE_ON_FREE,
|
|
|
|
get_config()->backlog,
|
|
|
|
fd);
|
|
|
|
evconnlistener_set_error_cb(evlistener, evlistener_errorcb);
|
|
|
|
return evlistener;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace {
|
2012-06-06 15:43:35 +02:00
|
|
|
evconnlistener* create_evlistener(ListenHandler *handler, int family)
|
2012-06-04 16:48:31 +02:00
|
|
|
{
|
2014-08-12 15:22:02 +02:00
|
|
|
{
|
|
|
|
auto envfd = getenv(family == AF_INET ?
|
|
|
|
ENV_LISTENER4_FD : ENV_LISTENER6_FD);
|
|
|
|
auto envport = getenv(ENV_PORT);
|
|
|
|
|
|
|
|
if(envfd && envport) {
|
|
|
|
auto fd = strtoul(envfd, nullptr, 10);
|
|
|
|
auto port = strtoul(envport, nullptr, 10);
|
|
|
|
|
|
|
|
// Only do this iff NGHTTPX_PORT == get_config()->port.
|
|
|
|
// Otherwise, close fd, and create server socket as usual.
|
|
|
|
|
|
|
|
if(port == get_config()->port) {
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Listening on port " << get_config()->port;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_evlistener(handler, fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(WARNING) << "Port was changed between old binary (" << port
|
|
|
|
<< ") and new binary (" << get_config()->port << ")";
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
addrinfo hints;
|
|
|
|
int fd = -1;
|
2014-07-06 12:21:18 +02:00
|
|
|
int rv;
|
2014-05-14 15:39:28 +02:00
|
|
|
|
|
|
|
auto service = util::utos(get_config()->port);
|
2012-06-04 16:48:31 +02:00
|
|
|
memset(&hints, 0, sizeof(addrinfo));
|
2012-06-06 15:43:35 +02:00
|
|
|
hints.ai_family = family;
|
2012-06-04 16:48:31 +02:00
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags = AI_PASSIVE;
|
|
|
|
#ifdef AI_ADDRCONFIG
|
|
|
|
hints.ai_flags |= AI_ADDRCONFIG;
|
|
|
|
#endif // AI_ADDRCONFIG
|
2012-06-06 15:43:35 +02:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
auto node = strcmp("*", get_config()->host.get()) == 0 ?
|
|
|
|
nullptr : get_config()->host.get();
|
2014-05-25 09:15:48 +02:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
addrinfo *res, *rp;
|
2014-07-06 12:21:18 +02:00
|
|
|
rv = getaddrinfo(node, service.c_str(), &hints, &res);
|
|
|
|
if(rv != 0) {
|
2013-01-21 14:42:49 +01:00
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Unable to get IPv" << (family == AF_INET ? "4" : "6")
|
2014-06-08 14:02:40 +02:00
|
|
|
<< " address for " << get_config()->host.get() << ": "
|
2014-07-06 12:21:18 +02:00
|
|
|
<< gai_strerror(rv);
|
2013-01-21 14:42:49 +01:00
|
|
|
}
|
2014-07-06 12:21:18 +02:00
|
|
|
return nullptr;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
for(rp = res; rp; rp = rp->ai_next) {
|
|
|
|
fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
|
|
|
if(fd == -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int val = 1;
|
|
|
|
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val,
|
|
|
|
static_cast<socklen_t>(sizeof(val))) == -1) {
|
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
evutil_make_socket_nonblocking(fd);
|
2012-06-06 15:43:35 +02:00
|
|
|
#ifdef IPV6_V6ONLY
|
|
|
|
if(family == AF_INET6) {
|
|
|
|
if(setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val,
|
|
|
|
static_cast<socklen_t>(sizeof(val))) == -1) {
|
|
|
|
close(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IPV6_V6ONLY
|
2012-06-04 16:48:31 +02:00
|
|
|
if(bind(fd, rp->ai_addr, rp->ai_addrlen) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
2014-07-06 12:21:18 +02:00
|
|
|
|
|
|
|
if(!rp) {
|
|
|
|
LOG(WARNING) << "Listening " << (family == AF_INET ? "IPv4" : "IPv6")
|
|
|
|
<< " socket failed";
|
|
|
|
|
2014-07-17 17:21:15 +02:00
|
|
|
freeaddrinfo(res);
|
|
|
|
|
2014-07-06 12:21:18 +02:00
|
|
|
return nullptr;
|
2012-06-06 15:43:35 +02:00
|
|
|
}
|
2014-07-06 12:21:18 +02:00
|
|
|
|
|
|
|
char host[NI_MAXHOST];
|
|
|
|
rv = getnameinfo(rp->ai_addr, rp->ai_addrlen, host, sizeof(host),
|
|
|
|
nullptr, 0, NI_NUMERICHOST);
|
|
|
|
|
2014-07-17 17:21:15 +02:00
|
|
|
freeaddrinfo(res);
|
|
|
|
|
2014-07-06 12:21:18 +02:00
|
|
|
if(rv != 0) {
|
|
|
|
LOG(WARNING) << gai_strerror(rv);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Listening on " << host << ", port " << get_config()->port;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2012-06-06 15:43:35 +02:00
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
return new_evlistener(handler, fd);
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-08-01 17:29:37 +02:00
|
|
|
namespace {
|
|
|
|
void drop_privileges()
|
|
|
|
{
|
|
|
|
if(getuid() == 0 && get_config()->uid != 0) {
|
|
|
|
if(setgid(get_config()->gid) != 0) {
|
2014-08-13 15:13:08 +02:00
|
|
|
auto error = errno;
|
|
|
|
LOG(FATAL) << "Could not change gid: " << strerror(error);
|
2012-08-01 17:29:37 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if(setuid(get_config()->uid) != 0) {
|
2014-08-13 15:13:08 +02:00
|
|
|
auto error = errno;
|
|
|
|
LOG(FATAL) << "Could not change uid: " << strerror(error);
|
2012-08-01 17:29:37 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if(setuid(0) != -1) {
|
|
|
|
LOG(FATAL) << "Still have root privileges?";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-08-10 11:55:18 +02:00
|
|
|
namespace {
|
|
|
|
void save_pid()
|
|
|
|
{
|
2014-06-08 14:02:40 +02:00
|
|
|
std::ofstream out(get_config()->pid_file.get(), std::ios::binary);
|
2013-08-10 11:55:18 +02:00
|
|
|
out << getpid() << "\n";
|
|
|
|
out.close();
|
|
|
|
if(!out) {
|
2014-06-08 14:02:40 +02:00
|
|
|
LOG(ERROR) << "Could not save PID to file "
|
|
|
|
<< get_config()->pid_file.get();
|
2013-08-10 11:55:18 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2014-08-12 18:53:44 +02:00
|
|
|
|
|
|
|
if(get_config()->uid != 0) {
|
|
|
|
if(chown(get_config()->pid_file.get(),
|
|
|
|
get_config()->uid, get_config()->gid) == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(WARNING) << "Changing owner of pid file "
|
|
|
|
<< get_config()->pid_file.get()
|
|
|
|
<< " failed: "
|
|
|
|
<< strerror(error);
|
|
|
|
}
|
|
|
|
}
|
2013-08-10 11:55:18 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-07-05 11:22:40 +02:00
|
|
|
namespace {
|
|
|
|
void reopen_log_signal_cb(evutil_socket_t sig, short events, void *arg)
|
|
|
|
{
|
|
|
|
auto listener_handler = static_cast<ListenHandler*>(arg);
|
|
|
|
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
2014-08-19 14:33:54 +02:00
|
|
|
LOG(INFO) << "Reopening log files: worker_info(" << worker_config << ")";
|
2014-07-05 11:22:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(void)reopen_log_files();
|
|
|
|
|
|
|
|
if(get_config()->num_worker > 1) {
|
|
|
|
listener_handler->worker_reopen_log_files();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
namespace {
|
|
|
|
void exec_binary_signal_cb(evutil_socket_t sig, short events, void *arg)
|
|
|
|
{
|
|
|
|
auto listener_handler = static_cast<ListenHandler*>(arg);
|
|
|
|
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Executing new binary";
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pid = fork();
|
|
|
|
|
|
|
|
if(pid == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(ERROR) << "fork() failed errno=" << error;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pid != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto exec_path = util::get_exec_path(get_config()->argc,
|
|
|
|
get_config()->argv,
|
|
|
|
get_config()->cwd);
|
|
|
|
|
|
|
|
if(!exec_path) {
|
|
|
|
LOG(ERROR) << "Could not resolve the executable path";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto argv =
|
|
|
|
static_cast<char**>(malloc(sizeof(char*) * (get_config()->argc + 1)));
|
|
|
|
|
|
|
|
argv[0] = exec_path;
|
|
|
|
for(int i = 1; i < get_config()->argc; ++i) {
|
|
|
|
argv[i] = strdup(get_config()->argv[i]);
|
|
|
|
}
|
|
|
|
argv[get_config()->argc] = nullptr;
|
|
|
|
|
|
|
|
size_t envlen = 0;
|
|
|
|
for(char **p = environ; *p; ++p, ++envlen);
|
|
|
|
// 3 for missing fd4, fd6 and port.
|
|
|
|
auto envp = static_cast<char**>(malloc(sizeof(char*) * (envlen + 3 + 1)));
|
|
|
|
size_t envidx = 0;
|
|
|
|
|
|
|
|
auto evlistener4 = listener_handler->get_evlistener4();
|
|
|
|
if(evlistener4) {
|
|
|
|
std::string fd4 = ENV_LISTENER4_FD "=";
|
|
|
|
fd4 += util::utos(evconnlistener_get_fd(evlistener4));
|
|
|
|
envp[envidx++] = strdup(fd4.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto evlistener6 = listener_handler->get_evlistener6();
|
|
|
|
if(evlistener6) {
|
|
|
|
std::string fd6 = ENV_LISTENER6_FD "=";
|
|
|
|
fd6 += util::utos(evconnlistener_get_fd(evlistener6));
|
|
|
|
envp[envidx++] = strdup(fd6.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string port = ENV_PORT "=";
|
|
|
|
port += util::utos(get_config()->port);
|
|
|
|
envp[envidx++] = strdup(port.c_str());
|
|
|
|
|
|
|
|
for(size_t i = 0; i < envlen; ++i) {
|
|
|
|
if(strcmp(ENV_LISTENER4_FD, environ[i]) == 0 ||
|
|
|
|
strcmp(ENV_LISTENER6_FD, environ[i]) == 0 ||
|
|
|
|
strcmp(ENV_PORT, environ[i]) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
envp[envidx++] = environ[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
envp[envidx++] = nullptr;
|
|
|
|
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "cmdline";
|
|
|
|
for(int i = 0; argv[i]; ++i) {
|
|
|
|
LOG(INFO) << i << ": " << argv[i];
|
|
|
|
}
|
|
|
|
LOG(INFO) << "environ";
|
|
|
|
for(int i = 0; envp[i]; ++i) {
|
|
|
|
LOG(INFO) << i << ": " << envp[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(execve(argv[0], argv, envp) == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(ERROR) << "execve failed: errno=" << error;
|
2014-08-23 11:15:47 +02:00
|
|
|
_Exit(EXIT_FAILURE);
|
2014-08-12 15:22:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void graceful_shutdown_signal_cb(evutil_socket_t sig, short events, void *arg)
|
|
|
|
{
|
|
|
|
auto listener_handler = static_cast<ListenHandler*>(arg);
|
|
|
|
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Graceful shutdown signal received";
|
|
|
|
}
|
|
|
|
|
|
|
|
listener_handler->disable_evlistener();
|
|
|
|
|
|
|
|
// After disabling accepting new connection, disptach incoming
|
|
|
|
// connection in backlog.
|
|
|
|
|
|
|
|
listener_handler->accept_pending_connection();
|
|
|
|
|
2014-08-19 14:33:54 +02:00
|
|
|
worker_config->graceful_shutdown = true;
|
2014-08-12 15:22:02 +02:00
|
|
|
|
|
|
|
listener_handler->graceful_shutdown_worker();
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-07-05 12:40:30 +02:00
|
|
|
namespace {
|
2014-07-06 06:27:51 +02:00
|
|
|
std::unique_ptr<std::string> generate_time()
|
2014-07-05 12:40:30 +02:00
|
|
|
{
|
2014-07-06 06:27:51 +02:00
|
|
|
char buf[32];
|
2014-07-05 12:40:30 +02:00
|
|
|
|
|
|
|
// Format data like this:
|
|
|
|
// 03/Jul/2014:00:19:38 +0900
|
|
|
|
struct tm tms;
|
|
|
|
auto now = time(nullptr);
|
|
|
|
|
|
|
|
if(localtime_r(&now, &tms) == nullptr) {
|
2014-07-06 06:27:51 +02:00
|
|
|
return util::make_unique<std::string>("");
|
2014-07-05 12:40:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 06:27:51 +02:00
|
|
|
if(strftime(buf, sizeof(buf), "%d/%b/%Y:%T %z", &tms) == 0) {
|
|
|
|
return util::make_unique<std::string>("");
|
2014-07-05 12:40:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 06:27:51 +02:00
|
|
|
return util::make_unique<std::string>(buf);
|
2014-07-05 12:40:30 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void refresh_cb(evutil_socket_t sig, short events, void *arg)
|
|
|
|
{
|
2014-08-12 15:22:02 +02:00
|
|
|
auto listener_handler = static_cast<ListenHandler*>(arg);
|
|
|
|
auto worker_stat = listener_handler->get_worker_stat();
|
|
|
|
|
2014-07-06 06:27:51 +02:00
|
|
|
mod_config()->cached_time = generate_time();
|
2014-08-12 15:22:02 +02:00
|
|
|
|
|
|
|
// In multi threaded mode (get_config()->num_worker > 1), we have to
|
|
|
|
// wait for event notification to workers to finish.
|
|
|
|
if(get_config()->num_worker == 1 &&
|
2014-08-19 14:33:54 +02:00
|
|
|
worker_config->graceful_shutdown &&
|
2014-08-12 15:22:02 +02:00
|
|
|
(!worker_stat || worker_stat->num_connections == 0)) {
|
|
|
|
event_base_loopbreak(listener_handler->get_evbase());
|
|
|
|
}
|
2014-07-05 12:40:30 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace {
|
|
|
|
int event_loop()
|
|
|
|
{
|
2014-07-05 11:22:40 +02:00
|
|
|
int rv;
|
|
|
|
|
2013-08-03 12:04:44 +02:00
|
|
|
auto evbase = event_base_new();
|
2013-09-24 16:17:53 +02:00
|
|
|
if(!evbase) {
|
|
|
|
LOG(FATAL) << "event_base_new() failed";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-02-09 09:45:57 +01:00
|
|
|
SSL_CTX *sv_ssl_ctx, *cl_ssl_ctx;
|
2012-06-06 15:43:35 +02:00
|
|
|
|
2013-02-09 09:45:57 +01:00
|
|
|
if(get_config()->client_mode) {
|
2013-08-03 12:04:44 +02:00
|
|
|
sv_ssl_ctx = nullptr;
|
2013-08-03 12:01:57 +02:00
|
|
|
cl_ssl_ctx = get_config()->downstream_no_tls ?
|
2013-08-03 12:04:44 +02:00
|
|
|
nullptr : ssl::create_ssl_client_context();
|
2013-02-09 09:45:57 +01:00
|
|
|
} else {
|
2013-08-03 12:01:57 +02:00
|
|
|
sv_ssl_ctx = get_config()->upstream_no_tls ?
|
2013-08-03 12:04:44 +02:00
|
|
|
nullptr : get_config()->default_ssl_ctx;
|
2013-11-04 10:14:05 +01:00
|
|
|
cl_ssl_ctx = get_config()->http2_bridge &&
|
2013-08-03 12:01:57 +02:00
|
|
|
!get_config()->downstream_no_tls ?
|
2013-08-03 12:04:44 +02:00
|
|
|
ssl::create_ssl_client_context() : nullptr;
|
2013-02-09 09:45:57 +01:00
|
|
|
}
|
2012-06-06 15:43:35 +02:00
|
|
|
|
2013-08-03 12:04:44 +02:00
|
|
|
auto listener_handler = new ListenHandler(evbase, sv_ssl_ctx, cl_ssl_ctx);
|
2012-10-28 06:29:27 +01:00
|
|
|
if(get_config()->daemon) {
|
|
|
|
if(daemon(0, 0) == -1) {
|
2014-08-13 15:13:08 +02:00
|
|
|
auto error = errno;
|
|
|
|
LOG(FATAL) << "Failed to daemonize: " << strerror(error);
|
2012-10-28 06:29:27 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-10 11:55:18 +02:00
|
|
|
if(get_config()->pid_file) {
|
|
|
|
save_pid();
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:34:59 +02:00
|
|
|
auto evlistener6 = create_evlistener(listener_handler, AF_INET6);
|
|
|
|
auto evlistener4 = create_evlistener(listener_handler, AF_INET);
|
2012-06-06 15:43:35 +02:00
|
|
|
if(!evlistener6 && !evlistener4) {
|
|
|
|
LOG(FATAL) << "Failed to listen on address "
|
2014-06-08 14:02:40 +02:00
|
|
|
<< get_config()->host.get() << ", port " << get_config()->port;
|
2012-06-06 16:58:19 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2012-06-06 15:43:35 +02:00
|
|
|
}
|
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
listener_handler->set_evlistener4(evlistener4);
|
|
|
|
listener_handler->set_evlistener6(evlistener6);
|
|
|
|
|
2013-04-19 13:58:58 +02:00
|
|
|
// ListenHandler loads private key, and we listen on a priveleged port.
|
|
|
|
// After that, we drop the root privileges if needed.
|
|
|
|
drop_privileges();
|
|
|
|
|
2014-07-05 12:43:39 +02:00
|
|
|
#ifndef NOTHREADS
|
2014-07-05 11:22:40 +02:00
|
|
|
sigset_t signals;
|
|
|
|
sigemptyset(&signals);
|
|
|
|
sigaddset(&signals, REOPEN_LOG_SIGNAL);
|
2014-08-12 15:22:02 +02:00
|
|
|
sigaddset(&signals, EXEC_BINARY_SIGNAL);
|
|
|
|
sigaddset(&signals, GRACEFUL_SHUTDOWN_SIGNAL);
|
2014-07-05 11:22:40 +02:00
|
|
|
rv = pthread_sigmask(SIG_BLOCK, &signals, nullptr);
|
|
|
|
if(rv != 0) {
|
2014-08-12 15:22:02 +02:00
|
|
|
LOG(ERROR) << "Blocking signals failed: " << strerror(rv);
|
2014-07-05 11:22:40 +02:00
|
|
|
}
|
2014-07-05 12:43:39 +02:00
|
|
|
#endif // !NOTHREADS
|
2014-07-05 11:22:40 +02:00
|
|
|
|
2012-06-05 18:26:04 +02:00
|
|
|
if(get_config()->num_worker > 1) {
|
|
|
|
listener_handler->create_worker_thread(get_config()->num_worker);
|
2013-11-04 10:15:56 +01:00
|
|
|
} else if(get_config()->downstream_proto == PROTO_HTTP2) {
|
2013-11-04 09:53:57 +01:00
|
|
|
listener_handler->create_http2_session();
|
2014-08-19 16:36:04 +02:00
|
|
|
} else {
|
|
|
|
listener_handler->create_http1_connect_blocker();
|
2012-06-05 18:26:04 +02:00
|
|
|
}
|
2012-06-06 15:43:35 +02:00
|
|
|
|
2014-07-05 12:43:39 +02:00
|
|
|
#ifndef NOTHREADS
|
2014-07-05 11:22:40 +02:00
|
|
|
rv = pthread_sigmask(SIG_UNBLOCK, &signals, nullptr);
|
|
|
|
if(rv != 0) {
|
2014-08-12 15:22:02 +02:00
|
|
|
LOG(ERROR) << "Unblocking signals failed: " << strerror(rv);
|
2014-07-05 11:22:40 +02:00
|
|
|
}
|
2014-07-05 12:43:39 +02:00
|
|
|
#endif // !NOTHREADS
|
2014-07-05 11:22:40 +02:00
|
|
|
|
|
|
|
auto reopen_log_signal_event = evsignal_new(evbase, REOPEN_LOG_SIGNAL,
|
|
|
|
reopen_log_signal_cb,
|
|
|
|
listener_handler);
|
|
|
|
|
|
|
|
if(!reopen_log_signal_event) {
|
|
|
|
LOG(ERROR) << "evsignal_new failed";
|
|
|
|
} else {
|
|
|
|
rv = event_add(reopen_log_signal_event, nullptr);
|
|
|
|
if(rv < 0) {
|
|
|
|
LOG(ERROR) << "event_add for reopen_log_signal_event failed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
auto exec_binary_signal_event = evsignal_new(evbase, EXEC_BINARY_SIGNAL,
|
|
|
|
exec_binary_signal_cb,
|
|
|
|
listener_handler);
|
|
|
|
rv = event_add(exec_binary_signal_event, nullptr);
|
|
|
|
|
|
|
|
if(rv == -1) {
|
|
|
|
LOG(FATAL) << "event_add for exec_binary_signal_event failed";
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto graceful_shutdown_signal_event = evsignal_new
|
|
|
|
(evbase, GRACEFUL_SHUTDOWN_SIGNAL, graceful_shutdown_signal_cb,
|
|
|
|
listener_handler);
|
|
|
|
|
|
|
|
rv = event_add(graceful_shutdown_signal_event, nullptr);
|
|
|
|
|
|
|
|
if(rv == -1) {
|
|
|
|
LOG(FATAL) << "event_add for graceful_shutdown_signal_event failed";
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-07-05 12:40:30 +02:00
|
|
|
auto refresh_event = event_new(evbase, -1, EV_PERSIST, refresh_cb,
|
2014-08-12 15:22:02 +02:00
|
|
|
listener_handler);
|
2014-07-05 12:40:30 +02:00
|
|
|
|
|
|
|
if(!refresh_event) {
|
|
|
|
LOG(ERROR) << "event_new failed";
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeval refresh_timeout = { 1, 0 };
|
|
|
|
rv = event_add(refresh_event, &refresh_timeout);
|
|
|
|
|
|
|
|
if(rv == -1) {
|
|
|
|
LOG(ERROR) << "Adding refresh_event failed";
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2013-01-21 14:42:49 +01:00
|
|
|
if(LOG_ENABLED(INFO)) {
|
2012-06-04 16:48:31 +02:00
|
|
|
LOG(INFO) << "Entering event loop";
|
|
|
|
}
|
|
|
|
event_base_loop(evbase, 0);
|
2014-07-05 11:22:40 +02:00
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
listener_handler->join_worker();
|
|
|
|
|
2014-07-05 12:40:30 +02:00
|
|
|
if(refresh_event) {
|
|
|
|
event_free(refresh_event);
|
|
|
|
}
|
2014-08-12 15:22:02 +02:00
|
|
|
if(graceful_shutdown_signal_event) {
|
|
|
|
event_free(graceful_shutdown_signal_event);
|
|
|
|
}
|
|
|
|
if(exec_binary_signal_event) {
|
|
|
|
event_free(exec_binary_signal_event);
|
|
|
|
}
|
2014-07-05 11:22:40 +02:00
|
|
|
if(reopen_log_signal_event) {
|
|
|
|
event_free(reopen_log_signal_event);
|
|
|
|
}
|
2012-06-06 15:43:35 +02:00
|
|
|
if(evlistener4) {
|
|
|
|
evconnlistener_free(evlistener4);
|
|
|
|
}
|
|
|
|
if(evlistener6) {
|
|
|
|
evconnlistener_free(evlistener6);
|
|
|
|
}
|
2012-06-04 16:48:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-08-01 17:06:41 +02:00
|
|
|
namespace {
|
|
|
|
// Returns true if regular file or symbolic link |path| exists.
|
|
|
|
bool conf_exists(const char *path)
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
int rv = stat(path, &buf);
|
|
|
|
return rv == 0 && (buf.st_mode & (S_IFREG | S_IFLNK));
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-09-23 13:55:39 +02:00
|
|
|
namespace {
|
|
|
|
const char *DEFAULT_NPN_LIST = NGHTTP2_PROTO_VERSION_ID ","
|
|
|
|
#ifdef HAVE_SPDYLAY
|
2013-11-12 03:03:46 +01:00
|
|
|
"spdy/3.1,spdy/3,spdy/2,"
|
2013-09-23 13:55:39 +02:00
|
|
|
#endif // HAVE_SPDYLAY
|
|
|
|
"http/1.1";
|
|
|
|
} // namespace
|
|
|
|
|
2014-01-02 03:49:38 +01:00
|
|
|
namespace {
|
2014-06-19 16:21:53 +02:00
|
|
|
const char *DEFAULT_TLS_PROTO_LIST = "TLSv1.2,TLSv1.1";
|
2014-01-02 03:49:38 +01:00
|
|
|
} // namespace
|
|
|
|
|
2012-06-06 16:58:19 +02:00
|
|
|
namespace {
|
|
|
|
void fill_default_config()
|
2012-06-04 16:48:31 +02:00
|
|
|
{
|
2012-11-22 15:35:10 +01:00
|
|
|
memset(mod_config(), 0, sizeof(*mod_config()));
|
|
|
|
|
|
|
|
mod_config()->verbose = false;
|
2012-06-06 17:03:05 +02:00
|
|
|
mod_config()->daemon = false;
|
|
|
|
|
2013-07-26 14:42:39 +02:00
|
|
|
mod_config()->server_name = "nghttpx nghttp2/" NGHTTP2_VERSION;
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->host = strcopy("*");
|
2012-06-04 16:48:31 +02:00
|
|
|
mod_config()->port = 3000;
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->private_key_file = nullptr;
|
|
|
|
mod_config()->private_key_passwd = nullptr;
|
|
|
|
mod_config()->cert_file = nullptr;
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2013-11-04 10:22:29 +01:00
|
|
|
// Read timeout for HTTP2 upstream connection
|
2014-08-09 15:59:31 +02:00
|
|
|
mod_config()->http2_upstream_read_timeout = {180, 0};
|
2012-07-17 17:13:11 +02:00
|
|
|
|
2013-11-04 10:22:29 +01:00
|
|
|
// Read timeout for non-HTTP2 upstream connection
|
2014-08-09 15:59:31 +02:00
|
|
|
mod_config()->upstream_read_timeout = {30, 0};
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2013-11-04 10:22:29 +01:00
|
|
|
// Write timeout for HTTP2/non-HTTP2 upstream connection
|
2014-08-09 15:59:31 +02:00
|
|
|
mod_config()->upstream_write_timeout = {30, 0};
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2012-07-17 17:13:11 +02:00
|
|
|
// Read/Write timeouts for downstream connection
|
2014-08-09 15:59:31 +02:00
|
|
|
mod_config()->downstream_read_timeout = {30, 0};
|
|
|
|
mod_config()->downstream_write_timeout = {30, 0};
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2014-08-09 11:47:45 +02:00
|
|
|
// Read timeout for HTTP/2 stream
|
2014-08-09 17:08:44 +02:00
|
|
|
mod_config()->stream_read_timeout = {0, 0};
|
2014-08-09 11:47:45 +02:00
|
|
|
|
|
|
|
// Write timeout for HTTP/2 stream
|
2014-08-09 17:08:44 +02:00
|
|
|
mod_config()->stream_write_timeout = {0, 0};
|
2014-08-09 11:47:45 +02:00
|
|
|
|
2012-07-17 17:13:11 +02:00
|
|
|
// Timeout for pooled (idle) connections
|
2014-08-09 15:59:31 +02:00
|
|
|
mod_config()->downstream_idle_read_timeout = {60, 0};
|
2012-06-12 16:02:01 +02:00
|
|
|
|
2014-03-30 12:09:21 +02:00
|
|
|
// window bits for HTTP/2 and SPDY upstream/downstream connection
|
|
|
|
// per stream. 2**16-1 = 64KiB-1, which is HTTP/2 default. Please
|
2013-08-03 12:53:07 +02:00
|
|
|
// note that SPDY/3 default is 64KiB.
|
2013-11-04 10:14:05 +01:00
|
|
|
mod_config()->http2_upstream_window_bits = 16;
|
|
|
|
mod_config()->http2_downstream_window_bits = 16;
|
2012-07-26 16:18:37 +02:00
|
|
|
|
2014-03-30 12:09:21 +02:00
|
|
|
// HTTP/2 SPDY/3.1 has connection-level flow control. The default
|
2013-11-20 16:15:17 +01:00
|
|
|
// window size for HTTP/2 is 64KiB - 1. SPDY/3's default is 64KiB
|
|
|
|
mod_config()->http2_upstream_connection_window_bits = 16;
|
|
|
|
mod_config()->http2_downstream_connection_window_bits = 16;
|
|
|
|
|
2013-08-03 12:01:57 +02:00
|
|
|
mod_config()->upstream_no_tls = false;
|
|
|
|
mod_config()->downstream_no_tls = false;
|
2013-02-22 13:54:07 +01:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->downstream_host = strcopy("127.0.0.1");
|
2012-06-04 16:48:31 +02:00
|
|
|
mod_config()->downstream_port = 80;
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->downstream_hostport = nullptr;
|
2012-11-22 15:35:10 +01:00
|
|
|
mod_config()->downstream_addrlen = 0;
|
2012-06-06 16:58:19 +02:00
|
|
|
|
2012-06-06 19:09:59 +02:00
|
|
|
mod_config()->num_worker = 1;
|
2013-11-04 10:14:05 +01:00
|
|
|
mod_config()->http2_max_concurrent_streams = 100;
|
2012-08-01 18:32:33 +02:00
|
|
|
mod_config()->add_x_forwarded_for = false;
|
2013-01-09 14:01:25 +01:00
|
|
|
mod_config()->no_via = false;
|
2014-07-05 11:22:40 +02:00
|
|
|
mod_config()->accesslog_file = nullptr;
|
|
|
|
mod_config()->accesslog_syslog = false;
|
2014-08-17 12:01:51 +02:00
|
|
|
#if defined(__ANDROID__) || defined(ANDROID)
|
|
|
|
// Android does not have /dev/stderr. Use /proc/self/fd/2 instead.
|
|
|
|
mod_config()->errorlog_file = strcopy("/proc/self/fd/2");
|
|
|
|
#else // !__ANDROID__ && ANDROID
|
2014-07-05 11:22:40 +02:00
|
|
|
mod_config()->errorlog_file = strcopy("/dev/stderr");
|
2014-08-17 12:01:51 +02:00
|
|
|
#endif // !__ANDROID__ && ANDROID
|
2014-07-05 11:22:40 +02:00
|
|
|
mod_config()->errorlog_syslog = false;
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->conf_path = strcopy("/etc/nghttpx/nghttpx.conf");
|
2012-08-01 18:20:18 +02:00
|
|
|
mod_config()->syslog_facility = LOG_DAEMON;
|
2012-08-01 18:28:59 +02:00
|
|
|
// Default accept() backlog
|
2013-12-26 13:39:00 +01:00
|
|
|
mod_config()->backlog = -1;
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->ciphers = nullptr;
|
2013-11-04 10:14:05 +01:00
|
|
|
mod_config()->http2_proxy = false;
|
|
|
|
mod_config()->http2_bridge = false;
|
2012-11-21 14:10:35 +01:00
|
|
|
mod_config()->client_proxy = false;
|
|
|
|
mod_config()->client = false;
|
2012-11-18 13:23:13 +01:00
|
|
|
mod_config()->client_mode = false;
|
2012-11-22 13:46:15 +01:00
|
|
|
mod_config()->insecure = false;
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->cacert = nullptr;
|
|
|
|
mod_config()->pid_file = nullptr;
|
2012-11-22 15:35:10 +01:00
|
|
|
mod_config()->uid = 0;
|
|
|
|
mod_config()->gid = 0;
|
2012-11-23 13:11:01 +01:00
|
|
|
mod_config()->backend_ipv4 = false;
|
|
|
|
mod_config()->backend_ipv6 = false;
|
2014-06-08 14:05:36 +02:00
|
|
|
mod_config()->cert_tree = nullptr;
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->downstream_http_proxy_userinfo = nullptr;
|
|
|
|
mod_config()->downstream_http_proxy_host = nullptr;
|
2013-02-09 08:42:01 +01:00
|
|
|
mod_config()->downstream_http_proxy_port = 0;
|
|
|
|
mod_config()->downstream_http_proxy_addrlen = 0;
|
2014-08-17 09:17:10 +02:00
|
|
|
mod_config()->rate_limit_cfg = nullptr;
|
|
|
|
mod_config()->read_rate = 0;
|
|
|
|
mod_config()->read_burst = 1 << 30;
|
|
|
|
mod_config()->write_rate = 0;
|
|
|
|
mod_config()->write_burst = 0;
|
2014-03-09 06:53:28 +01:00
|
|
|
mod_config()->worker_read_rate = 0;
|
|
|
|
mod_config()->worker_read_burst = 0;
|
|
|
|
mod_config()->worker_write_rate = 0;
|
|
|
|
mod_config()->worker_write_burst = 0;
|
2014-06-19 16:19:14 +02:00
|
|
|
mod_config()->worker_rate_limit_cfg = nullptr;
|
2013-11-01 17:10:18 +01:00
|
|
|
mod_config()->verify_client = false;
|
2013-11-02 13:30:32 +01:00
|
|
|
mod_config()->verify_client_cacert = nullptr;
|
2013-11-02 14:58:02 +01:00
|
|
|
mod_config()->client_private_key_file = nullptr;
|
|
|
|
mod_config()->client_cert_file = nullptr;
|
2013-11-17 15:52:19 +01:00
|
|
|
mod_config()->http2_upstream_dump_request_header = nullptr;
|
|
|
|
mod_config()->http2_upstream_dump_response_header = nullptr;
|
2013-11-17 16:03:55 +01:00
|
|
|
mod_config()->http2_no_cookie_crumbling = false;
|
2014-02-09 10:47:26 +01:00
|
|
|
mod_config()->upstream_frame_debug = false;
|
2014-02-11 09:23:22 +01:00
|
|
|
mod_config()->padding = 0;
|
2014-06-26 15:55:22 +02:00
|
|
|
mod_config()->worker_frontend_connections = 0;
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-04-04 14:57:47 +02:00
|
|
|
nghttp2_option_new(&mod_config()->http2_option);
|
|
|
|
|
2014-07-25 14:26:03 +02:00
|
|
|
nghttp2_option_set_no_auto_window_update
|
2014-04-04 14:57:47 +02:00
|
|
|
(mod_config()->http2_option, 1);
|
2014-06-08 15:52:27 +02:00
|
|
|
|
|
|
|
mod_config()->tls_proto_mask = 0;
|
2014-07-06 06:27:51 +02:00
|
|
|
mod_config()->cached_time = generate_time();
|
2014-08-10 05:39:27 +02:00
|
|
|
mod_config()->no_location_rewrite = false;
|
2014-08-12 15:22:02 +02:00
|
|
|
mod_config()->argc = 0;
|
|
|
|
mod_config()->argv = nullptr;
|
2014-08-16 14:29:20 +02:00
|
|
|
mod_config()->max_downstream_connections = 100;
|
2013-09-13 14:23:55 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
size_t get_rate_limit(size_t rate_limit)
|
|
|
|
{
|
|
|
|
if(rate_limit == 0) {
|
|
|
|
return EV_RATE_LIMIT_MAX;
|
|
|
|
} else {
|
|
|
|
return rate_limit;
|
|
|
|
}
|
2012-06-06 16:58:19 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-11-22 15:08:36 +01:00
|
|
|
namespace {
|
|
|
|
void print_version(std::ostream& out)
|
|
|
|
{
|
|
|
|
out << get_config()->server_name << std::endl;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-06-06 16:58:19 +02:00
|
|
|
namespace {
|
|
|
|
void print_usage(std::ostream& out)
|
|
|
|
{
|
2014-03-22 14:03:13 +01:00
|
|
|
out << R"(Usage: nghttpx [OPTIONS]... [<PRIVATE_KEY> <CERT>]
|
|
|
|
A reverse proxy for HTTP/2, HTTP/1 and SPDY.)" << std::endl;
|
2012-06-06 16:58:19 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void print_help(std::ostream& out)
|
|
|
|
{
|
|
|
|
print_usage(out);
|
2014-03-22 14:03:13 +01:00
|
|
|
out << R"(
|
|
|
|
<PRIVATE_KEY> Set path to server's private key. Required
|
|
|
|
unless -p, --client or --frontend-no-tls are
|
|
|
|
given.
|
|
|
|
<CERT> Set path to server's certificate. Required
|
|
|
|
unless -p, --client or --frontend-no-tls are
|
|
|
|
given.
|
|
|
|
Options:
|
|
|
|
The options are categorized into several groups.
|
|
|
|
|
|
|
|
Connections:
|
|
|
|
-b, --backend=<HOST,PORT>
|
|
|
|
Set backend host and port.
|
|
|
|
Default: ')"
|
2014-06-08 14:02:40 +02:00
|
|
|
<< get_config()->downstream_host.get() << ","
|
2014-03-22 14:03:13 +01:00
|
|
|
<< get_config()->downstream_port << R"('
|
|
|
|
-f, --frontend=<HOST,PORT>
|
2014-05-25 09:15:48 +02:00
|
|
|
Set frontend host and port. If <HOST> is '*', it
|
|
|
|
assumes all addresses including both IPv4 and
|
|
|
|
IPv6.
|
2014-03-22 14:03:13 +01:00
|
|
|
Default: ')"
|
2014-06-08 14:02:40 +02:00
|
|
|
<< get_config()->host.get() << "," << get_config()->port << R"('
|
2014-03-22 14:03:13 +01:00
|
|
|
--backlog=<NUM> Set listen backlog size. If -1 is given,
|
|
|
|
libevent will choose suitable value.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->backlog << R"(
|
|
|
|
--backend-ipv4 Resolve backend hostname to IPv4 address only.
|
|
|
|
--backend-ipv6 Resolve backend hostname to IPv6 address only.
|
|
|
|
|
|
|
|
Performance:
|
|
|
|
-n, --workers=<CORES>
|
|
|
|
Set the number of worker threads.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->num_worker << R"(
|
2014-08-17 09:17:10 +02:00
|
|
|
--read-rate=<RATE>
|
|
|
|
Set maximum average read rate on frontend
|
|
|
|
connection. Setting 0 to this option means read
|
|
|
|
rate is unlimited.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->read_rate << R"(
|
|
|
|
--read-burst=<SIZE>
|
|
|
|
Set maximum read burst size on frontend
|
2014-08-17 15:31:44 +02:00
|
|
|
connection. Setting 0 does not work, but it is
|
|
|
|
not a problem because --read-rate=0 will give
|
|
|
|
unlimited read rate regardless of this option
|
|
|
|
value.
|
2014-08-17 09:17:10 +02:00
|
|
|
Default: )"
|
|
|
|
<< get_config()->read_burst << R"(
|
|
|
|
--write-rate=<RATE>
|
|
|
|
Set maximum average write rate on frontend
|
|
|
|
connection. Setting 0 to this option means write
|
|
|
|
rate is unlimited.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->write_rate << R"(
|
|
|
|
--write-burst=<SIZE>
|
|
|
|
Set maximum write burst size on frontend
|
|
|
|
connection. Setting 0 to this option means write
|
|
|
|
burst size is unlimited.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->write_burst << R"(
|
2014-03-22 14:03:13 +01:00
|
|
|
--worker-read-rate=<RATE>
|
|
|
|
Set maximum average read rate on frontend
|
|
|
|
connection per worker. Setting 0 to this option
|
|
|
|
means read rate is unlimited.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->worker_read_rate << R"(
|
|
|
|
--worker-read-burst=<SIZE>
|
|
|
|
Set maximum read burst size on frontend
|
|
|
|
connection per worker. Setting 0 to this option
|
|
|
|
means read burst size is unlimited.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->worker_read_burst << R"(
|
|
|
|
--worker-write-rate=<RATE>
|
|
|
|
Set maximum average write rate on frontend
|
|
|
|
connection per worker. Setting 0 to this option
|
|
|
|
means write rate is unlimited.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->worker_write_rate << R"(
|
|
|
|
--worker-write-burst=<SIZE>
|
|
|
|
Set maximum write burst size on frontend
|
|
|
|
connection per worker. Setting 0 to this option
|
|
|
|
means write burst size is unlimited.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->worker_write_burst << R"(
|
2014-06-26 15:55:22 +02:00
|
|
|
--worker-frontend-connections=<NUM>
|
|
|
|
Set maximum number of simultaneous connections
|
|
|
|
frontend accepts. Setting 0 means unlimited.
|
|
|
|
Default: 0
|
2014-08-16 14:29:20 +02:00
|
|
|
--backend-connections-per-frontend=<NUM>
|
|
|
|
Set maximum number of backend simultaneous
|
|
|
|
connections per frontend. This option is
|
|
|
|
meaningful when the combination of HTTP/2 or SPDY
|
|
|
|
frontend and HTTP/1 backend is used.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->max_downstream_connections << R"(
|
2014-03-22 14:03:13 +01:00
|
|
|
|
|
|
|
Timeout:
|
|
|
|
--frontend-http2-read-timeout=<SEC>
|
|
|
|
Specify read timeout for HTTP/2 and SPDY frontend
|
|
|
|
connection.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->http2_upstream_read_timeout.tv_sec << R"(
|
|
|
|
--frontend-read-timeout=<SEC>
|
|
|
|
Specify read timeout for HTTP/1.1 frontend
|
|
|
|
connection.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->upstream_read_timeout.tv_sec << R"(
|
|
|
|
--frontend-write-timeout=<SEC>
|
|
|
|
Specify write timeout for all frontend
|
|
|
|
connections.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->upstream_write_timeout.tv_sec << R"(
|
2014-08-09 11:47:45 +02:00
|
|
|
--stream-read-timeout=<SEC>
|
|
|
|
Specify read timeout for HTTP/2 and SPDY streams.
|
2014-08-09 17:08:44 +02:00
|
|
|
0 means no timeout.
|
2014-08-09 11:47:45 +02:00
|
|
|
Default: )"
|
|
|
|
<< get_config()->stream_read_timeout.tv_sec << R"(
|
|
|
|
--stream-write-timeout=<SEC>
|
|
|
|
Specify write timeout for HTTP/2 and SPDY
|
2014-08-09 17:08:44 +02:00
|
|
|
streams. 0 means no timeout.
|
2014-08-09 11:47:45 +02:00
|
|
|
Default: )"
|
|
|
|
<< get_config()->stream_write_timeout.tv_sec << R"(
|
2014-03-22 14:03:13 +01:00
|
|
|
--backend-read-timeout=<SEC>
|
|
|
|
Specify read timeout for backend connection.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->downstream_read_timeout.tv_sec << R"(
|
|
|
|
--backend-write-timeout=<SEC>
|
|
|
|
Specify write timeout for backend connection.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->downstream_write_timeout.tv_sec << R"(
|
|
|
|
--backend-keep-alive-timeout=<SEC>
|
|
|
|
Specify keep-alive timeout for backend
|
|
|
|
connection.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->downstream_idle_read_timeout.tv_sec << R"(
|
|
|
|
--backend-http-proxy-uri=<URI>
|
|
|
|
Specify proxy URI in the form
|
|
|
|
http://[<USER>:<PASS>@]<PROXY>:<PORT>. If a
|
|
|
|
proxy requires authentication, specify <USER> and
|
|
|
|
<PASS>. Note that they must be properly
|
|
|
|
percent-encoded. This proxy is used when the
|
|
|
|
backend connection is HTTP/2. First, make a
|
|
|
|
CONNECT request to the proxy and it connects to
|
|
|
|
the backend on behalf of nghttpx. This forms
|
|
|
|
tunnel. After that, nghttpx performs SSL/TLS
|
|
|
|
handshake with the downstream through the tunnel.
|
|
|
|
The timeouts when connecting and making CONNECT
|
|
|
|
request can be specified by
|
|
|
|
--backend-read-timeout and
|
|
|
|
--backend-write-timeout options.
|
|
|
|
|
|
|
|
SSL/TLS:
|
|
|
|
--ciphers=<SUITE> Set allowed cipher list. The format of the
|
2014-06-10 15:47:22 +02:00
|
|
|
string is described in OpenSSL ciphers(1).
|
2014-03-22 14:03:13 +01:00
|
|
|
-k, --insecure
|
|
|
|
Don't verify backend server's certificate if -p,
|
|
|
|
--client or --http2-bridge are given and
|
|
|
|
--backend-no-tls is not given.
|
|
|
|
--cacert=<PATH> Set path to trusted CA certificate file if -p,
|
|
|
|
--client or --http2-bridge are given and
|
|
|
|
--backend-no-tls is not given. The file must be
|
|
|
|
in PEM format. It can contain multiple
|
|
|
|
certificates. If the linked OpenSSL is
|
|
|
|
configured to load system wide certificates, they
|
|
|
|
are loaded at startup regardless of this option.
|
|
|
|
--private-key-passwd-file=<FILEPATH>
|
|
|
|
Path to file that contains password for the
|
|
|
|
server's private key. If none is given and the
|
|
|
|
private key is password protected it'll be
|
|
|
|
requested interactively.
|
|
|
|
--subcert=<KEYPATH>:<CERTPATH>
|
|
|
|
Specify additional certificate and private key
|
|
|
|
file. nghttpx will choose certificates based on
|
|
|
|
the hostname indicated by client using TLS SNI
|
|
|
|
extension. This option can be used multiple
|
|
|
|
times.
|
|
|
|
--backend-tls-sni-field=<HOST>
|
|
|
|
Explicitly set the content of the TLS SNI
|
|
|
|
extension. This will default to the backend HOST
|
|
|
|
name.
|
|
|
|
--dh-param-file=<PATH>
|
|
|
|
Path to file that contains DH parameters in PEM
|
|
|
|
format. Without this option, DHE cipher suites
|
|
|
|
are not available.
|
2014-05-21 14:28:58 +02:00
|
|
|
--npn-list=<LIST> Comma delimited list of ALPN protocol identifier
|
|
|
|
sorted in the order of preference. That means
|
|
|
|
most desirable protocol comes first. This is
|
|
|
|
used in both ALPN and NPN. The parameter must be
|
|
|
|
delimited by a single comma only and any white
|
|
|
|
spaces are treated as a part of protocol string.
|
2014-03-22 14:03:13 +01:00
|
|
|
Default: )" << DEFAULT_NPN_LIST << R"(
|
|
|
|
--verify-client Require and verify client certificate.
|
|
|
|
--verify-client-cacert=<PATH>
|
|
|
|
Path to file that contains CA certificates to
|
|
|
|
verify client certificate. The file must be in
|
|
|
|
PEM format. It can contain multiple
|
|
|
|
certificates.
|
|
|
|
--client-private-key-file=<PATH>
|
|
|
|
Path to file that contains client private key
|
|
|
|
used in backend client authentication.
|
|
|
|
--client-cert-file=<PATH>
|
|
|
|
Path to file that contains client certificate
|
|
|
|
used in backend client authentication.
|
|
|
|
--tls-proto-list=<LIST>
|
|
|
|
Comma delimited list of SSL/TLS protocol to be
|
|
|
|
enabled. The following protocols are available:
|
|
|
|
TLSv1.2, TLSv1.1, TLSv1.0 and SSLv3. The name
|
|
|
|
matching is done in case-insensitive manner. The
|
|
|
|
parameter must be delimited by a single comma
|
|
|
|
only and any white spaces are treated as a part
|
|
|
|
of protocol string.
|
|
|
|
Default: )" << DEFAULT_TLS_PROTO_LIST << R"(
|
|
|
|
|
|
|
|
HTTP/2 and SPDY:
|
|
|
|
-c, --http2-max-concurrent-streams=<NUM>
|
|
|
|
Set the maximum number of the concurrent streams
|
|
|
|
in one HTTP/2 and SPDY session.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->http2_max_concurrent_streams << R"(
|
|
|
|
--frontend-http2-window-bits=<N>
|
|
|
|
Sets the per-stream initial window size of HTTP/2
|
|
|
|
SPDY frontend connection. For HTTP/2, the size
|
|
|
|
is 2**<N>-1. For SPDY, the size is 2**<N>.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->http2_upstream_window_bits << R"(
|
|
|
|
--frontend-http2-connection-window-bits=<N>
|
|
|
|
Sets the per-connection window size of HTTP/2 and
|
|
|
|
SPDY frontend connection. For HTTP/2, the size
|
|
|
|
is 2**<N>-1. For SPDY, the size is 2**<N>.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->http2_upstream_connection_window_bits << R"(
|
|
|
|
--frontend-no-tls Disable SSL/TLS on frontend connections.
|
|
|
|
--backend-http2-window-bits=<N>
|
|
|
|
Sets the initial window size of HTTP/2 backend
|
|
|
|
connection to 2**<N>-1.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->http2_downstream_window_bits << R"(
|
|
|
|
--backend-http2-connection-window-bits=<N>
|
|
|
|
Sets the per-connection window size of HTTP/2
|
|
|
|
backend connection to 2**<N>-1.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->http2_downstream_connection_window_bits << R"(
|
|
|
|
--backend-no-tls Disable SSL/TLS on backend connections.
|
|
|
|
--http2-no-cookie-crumbling
|
|
|
|
Don't crumble cookie header field.
|
|
|
|
--padding=<N> Add at most <N> bytes to a HTTP/2 frame payload
|
|
|
|
as padding. Specify 0 to disable padding. This
|
|
|
|
option is meant for debugging purpose and not
|
|
|
|
intended to enhance protocol security.
|
|
|
|
|
|
|
|
Mode:
|
|
|
|
(default mode) Accept HTTP/2, SPDY and HTTP/1.1 over SSL/TLS.
|
|
|
|
If --frontend-no-tls is used, accept HTTP/2 and
|
|
|
|
HTTP/1.1. The incoming HTTP/1.1 connection can
|
|
|
|
be upgraded to HTTP/2 through HTTP Upgrade. The
|
|
|
|
protocol to the backend is HTTP/1.1.
|
|
|
|
-s, --http2-proxy Like default mode, but enable secure proxy mode.
|
|
|
|
--http2-bridge Like default mode, but communicate with the
|
|
|
|
backend in HTTP/2 over SSL/TLS. Thus the
|
|
|
|
incoming all connections are converted to HTTP/2
|
|
|
|
connection and relayed to the backend. See
|
|
|
|
--backend-http-proxy-uri option if you are behind
|
|
|
|
the proxy and want to connect to the outside
|
|
|
|
HTTP/2 proxy.
|
|
|
|
--client Accept HTTP/2 and HTTP/1.1 without SSL/TLS. The
|
|
|
|
incoming HTTP/1.1 connection can be upgraded to
|
|
|
|
HTTP/2 connection through HTTP Upgrade. The
|
|
|
|
protocol to the backend is HTTP/2. To use
|
|
|
|
nghttpx as a forward proxy, use -p option
|
|
|
|
instead.
|
|
|
|
-p, --client-proxy
|
|
|
|
Like --client option, but it also requires the
|
|
|
|
request path from frontend must be an absolute
|
|
|
|
URI, suitable for use as a forward proxy.
|
|
|
|
|
|
|
|
Logging:
|
|
|
|
-L, --log-level=<LEVEL>
|
|
|
|
Set the severity level of log output. <LEVEL>
|
|
|
|
must be one of INFO, WARNING, ERROR and FATAL.
|
|
|
|
Default: WARNING
|
2014-07-05 11:22:40 +02:00
|
|
|
--accesslog-file=<PATH>
|
|
|
|
Set path to write access log. To reopen file,
|
|
|
|
send USR1 signal to nghttpx.
|
|
|
|
--accesslog-syslog
|
|
|
|
Send access log to syslog. If this option is
|
|
|
|
used, --access-file option is ignored.
|
|
|
|
--errorlog-file=<PATH>
|
|
|
|
Set path to write error log. To reopen file,
|
|
|
|
send USR1 signal to nghttpx.
|
|
|
|
Default: )"
|
|
|
|
<< get_config()->errorlog_file.get() << R"(
|
|
|
|
--errorlog-syslog Send error log to syslog. If this option is
|
|
|
|
used, --errorlog-file option is ignored.
|
2014-03-22 14:03:13 +01:00
|
|
|
--syslog-facility=<FACILITY>
|
|
|
|
Set syslog facility to <FACILITY>.
|
|
|
|
Default: )"
|
|
|
|
<< str_syslog_facility(get_config()->syslog_facility) << R"(
|
|
|
|
|
|
|
|
Misc:
|
|
|
|
--add-x-forwarded-for
|
|
|
|
Append X-Forwarded-For header field to the
|
|
|
|
downstream request.
|
|
|
|
--no-via Don't append to Via header field. If Via header
|
|
|
|
field is received, it is left unaltered.
|
2014-08-10 05:39:27 +02:00
|
|
|
--no-location-rewrite
|
|
|
|
Don't rewrite location header field on
|
|
|
|
--http2-bridge, --client and default mode. For
|
|
|
|
--http2-proxy and --client-proxy mode, location
|
|
|
|
header field will not be altered regardless of
|
|
|
|
this option.
|
2014-04-08 15:28:50 +02:00
|
|
|
--altsvc=<PROTOID,PORT[,HOST,[ORIGIN]]>
|
|
|
|
Specify protocol ID, port, host and origin of
|
|
|
|
alternative service. <HOST> and <ORIGIN> are
|
|
|
|
optional. They are advertised in alt-svc header
|
|
|
|
field or HTTP/2 ALTSVC frame. This option can be
|
|
|
|
used multiple times to specify multiple
|
|
|
|
alternative services. Example: --altsvc=h2,443
|
2014-04-26 07:56:08 +02:00
|
|
|
--add-response-header=<HEADER>
|
|
|
|
Specify additional header field to add to
|
|
|
|
response header set. This option just appends
|
|
|
|
header field and won't replace anything already
|
|
|
|
set. This option can be used several times to
|
|
|
|
specify multiple header fields.
|
|
|
|
Example: --add-response-header="foo: bar"
|
2014-03-22 14:03:13 +01:00
|
|
|
--frontend-http2-dump-request-header=<PATH>
|
|
|
|
Dumps request headers received by HTTP/2 frontend
|
|
|
|
to the file denoted in <PATH>. The output is
|
|
|
|
done in HTTP/1 header field format and each
|
|
|
|
header block is followed by an empty line. This
|
|
|
|
option is not thread safe and MUST NOT be used
|
|
|
|
with option -n<N>, where <N> >= 2.
|
|
|
|
--frontend-http2-dump-response-header=<PATH>
|
|
|
|
Dumps response headers sent from HTTP/2 frontend
|
|
|
|
to the file denoted in <PATH>. The output is
|
|
|
|
done in HTTP/1 header field format and each
|
|
|
|
header block is followed by an empty line. This
|
|
|
|
option is not thread safe and MUST NOT be used
|
|
|
|
with option -n<N>, where <N> >= 2.
|
|
|
|
-o, --frontend-frame-debug
|
|
|
|
Print HTTP/2 frames in frontend to stderr. This
|
|
|
|
option is not thread safe and MUST NOT be used
|
|
|
|
with option -n=N, where N >= 2.
|
|
|
|
-D, --daemon
|
|
|
|
Run in a background. If -D is used, the current
|
|
|
|
working directory is changed to '/'.
|
|
|
|
--pid-file=<PATH> Set path to save PID of this program.
|
|
|
|
--user=<USER> Run this program as <USER>. This option is
|
|
|
|
intended to be used to drop root privileges.
|
|
|
|
--conf=<PATH> Load configuration from <PATH>.
|
|
|
|
Default: )"
|
2014-06-08 14:02:40 +02:00
|
|
|
<< get_config()->conf_path.get() << R"(
|
2014-03-22 14:03:13 +01:00
|
|
|
-v, --version Print version and exit.
|
|
|
|
-h, --help Print this help and exit.)"
|
2012-06-06 16:58:19 +02:00
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
Log::set_severity_level(WARNING);
|
|
|
|
create_config();
|
|
|
|
fill_default_config();
|
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
// We have to copy argv, since getopt_long may change its content.
|
|
|
|
mod_config()->argc = argc;
|
|
|
|
mod_config()->argv = new char*[argc];
|
|
|
|
|
|
|
|
for(int i = 0; i < argc; ++i) {
|
|
|
|
mod_config()->argv[i] = strdup(argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
char cwd[PATH_MAX];
|
|
|
|
|
|
|
|
mod_config()->cwd = getcwd(cwd, sizeof(cwd));
|
|
|
|
if(mod_config()->cwd == nullptr) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(FATAL) << "failed to get current working directory: errno=" << error;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:06:41 +02:00
|
|
|
std::vector<std::pair<const char*, const char*> > cmdcfgs;
|
2012-06-06 16:58:19 +02:00
|
|
|
while(1) {
|
2014-04-30 15:44:51 +02:00
|
|
|
static int flag = 0;
|
2012-06-06 16:58:19 +02:00
|
|
|
static option long_options[] = {
|
2013-08-18 15:08:40 +02:00
|
|
|
{"daemon", no_argument, nullptr, 'D'},
|
|
|
|
{"log-level", required_argument, nullptr, 'L'},
|
|
|
|
{"backend", required_argument, nullptr, 'b'},
|
2013-11-04 10:14:05 +01:00
|
|
|
{"http2-max-concurrent-streams", required_argument, nullptr, 'c'},
|
2013-08-18 15:08:40 +02:00
|
|
|
{"frontend", required_argument, nullptr, 'f'},
|
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
|
|
{"insecure", no_argument, nullptr, 'k'},
|
|
|
|
{"workers", required_argument, nullptr, 'n'},
|
|
|
|
{"client-proxy", no_argument, nullptr, 'p'},
|
2013-11-04 10:14:05 +01:00
|
|
|
{"http2-proxy", no_argument, nullptr, 's'},
|
2013-08-18 15:08:40 +02:00
|
|
|
{"version", no_argument, nullptr, 'v'},
|
2014-02-09 10:47:26 +01:00
|
|
|
{"frontend-frame-debug", no_argument, nullptr, 'o'},
|
2013-08-18 15:08:40 +02:00
|
|
|
{"add-x-forwarded-for", no_argument, &flag, 1},
|
2013-11-04 10:14:05 +01:00
|
|
|
{"frontend-http2-read-timeout", required_argument, &flag, 2},
|
2013-08-18 15:08:40 +02:00
|
|
|
{"frontend-read-timeout", required_argument, &flag, 3},
|
|
|
|
{"frontend-write-timeout", required_argument, &flag, 4},
|
|
|
|
{"backend-read-timeout", required_argument, &flag, 5},
|
|
|
|
{"backend-write-timeout", required_argument, &flag, 6},
|
2014-07-05 11:22:40 +02:00
|
|
|
{"accesslog-file", required_argument, &flag, 7},
|
2013-08-18 15:08:40 +02:00
|
|
|
{"backend-keep-alive-timeout", required_argument, &flag, 8},
|
2013-11-04 10:14:05 +01:00
|
|
|
{"frontend-http2-window-bits", required_argument, &flag, 9},
|
2013-08-18 15:08:40 +02:00
|
|
|
{"pid-file", required_argument, &flag, 10},
|
|
|
|
{"user", required_argument, &flag, 11},
|
|
|
|
{"conf", required_argument, &flag, 12},
|
|
|
|
{"syslog-facility", required_argument, &flag, 14},
|
|
|
|
{"backlog", required_argument, &flag, 15},
|
|
|
|
{"ciphers", required_argument, &flag, 16},
|
|
|
|
{"client", no_argument, &flag, 17},
|
2013-11-04 10:14:05 +01:00
|
|
|
{"backend-http2-window-bits", required_argument, &flag, 18},
|
2013-08-18 15:08:40 +02:00
|
|
|
{"cacert", required_argument, &flag, 19},
|
|
|
|
{"backend-ipv4", no_argument, &flag, 20},
|
|
|
|
{"backend-ipv6", no_argument, &flag, 21},
|
2012-12-03 07:33:04 +01:00
|
|
|
{"private-key-passwd-file", required_argument, &flag, 22},
|
2013-01-09 14:01:25 +01:00
|
|
|
{"no-via", no_argument, &flag, 23},
|
2013-02-06 15:27:05 +01:00
|
|
|
{"subcert", required_argument, &flag, 24},
|
2013-11-04 10:14:05 +01:00
|
|
|
{"http2-bridge", no_argument, &flag, 25},
|
2013-02-09 08:42:01 +01:00
|
|
|
{"backend-http-proxy-uri", required_argument, &flag, 26},
|
2013-08-03 11:58:14 +02:00
|
|
|
{"backend-no-tls", no_argument, &flag, 27},
|
|
|
|
{"frontend-no-tls", no_argument, &flag, 29},
|
2013-03-29 14:06:33 +01:00
|
|
|
{"backend-tls-sni-field", required_argument, &flag, 31},
|
2013-08-30 15:07:42 +02:00
|
|
|
{"dh-param-file", required_argument, &flag, 33},
|
2014-08-17 09:17:10 +02:00
|
|
|
{"read-rate", required_argument, &flag, 34},
|
|
|
|
{"read-burst", required_argument, &flag, 35},
|
|
|
|
{"write-rate", required_argument, &flag, 36},
|
|
|
|
{"write-burst", required_argument, &flag, 37},
|
2013-09-23 13:55:39 +02:00
|
|
|
{"npn-list", required_argument, &flag, 38},
|
2013-11-01 17:10:18 +01:00
|
|
|
{"verify-client", no_argument, &flag, 39},
|
2013-11-02 13:30:32 +01:00
|
|
|
{"verify-client-cacert", required_argument, &flag, 40},
|
2013-11-02 14:58:02 +01:00
|
|
|
{"client-private-key-file", required_argument, &flag, 41},
|
|
|
|
{"client-cert-file", required_argument, &flag, 42},
|
2013-11-17 15:52:19 +01:00
|
|
|
{"frontend-http2-dump-request-header", required_argument, &flag, 43},
|
|
|
|
{"frontend-http2-dump-response-header", required_argument, &flag, 44},
|
2013-11-17 16:03:55 +01:00
|
|
|
{"http2-no-cookie-crumbling", no_argument, &flag, 45},
|
2013-11-20 16:15:17 +01:00
|
|
|
{"frontend-http2-connection-window-bits", required_argument, &flag, 46},
|
|
|
|
{"backend-http2-connection-window-bits", required_argument, &flag, 47},
|
2014-01-02 03:49:38 +01:00
|
|
|
{"tls-proto-list", required_argument, &flag, 48},
|
2014-02-11 09:23:22 +01:00
|
|
|
{"padding", required_argument, &flag, 49},
|
2014-03-09 06:53:28 +01:00
|
|
|
{"worker-read-rate", required_argument, &flag, 50},
|
|
|
|
{"worker-read-burst", required_argument, &flag, 51},
|
|
|
|
{"worker-write-rate", required_argument, &flag, 52},
|
|
|
|
{"worker-write-burst", required_argument, &flag, 53},
|
2014-04-08 15:28:50 +02:00
|
|
|
{"altsvc", required_argument, &flag, 54},
|
2014-04-26 07:56:08 +02:00
|
|
|
{"add-response-header", required_argument, &flag, 55},
|
2014-06-26 15:55:22 +02:00
|
|
|
{"worker-frontend-connections", required_argument, &flag, 56},
|
2014-07-05 11:22:40 +02:00
|
|
|
{"accesslog-syslog", no_argument, &flag, 57},
|
|
|
|
{"errorlog-file", required_argument, &flag, 58},
|
|
|
|
{"errorlog-syslog", no_argument, &flag, 59},
|
2014-08-09 11:47:45 +02:00
|
|
|
{"stream-read-timeout", required_argument, &flag, 60},
|
|
|
|
{"stream-write-timeout", required_argument, &flag, 61},
|
2014-08-10 05:39:27 +02:00
|
|
|
{"no-location-rewrite", no_argument, &flag, 62},
|
2014-08-16 14:29:20 +02:00
|
|
|
{"backend-connections-per-frontend", required_argument, &flag, 63},
|
2013-08-18 15:08:40 +02:00
|
|
|
{nullptr, 0, nullptr, 0 }
|
2012-06-06 16:58:19 +02:00
|
|
|
};
|
2013-11-02 14:58:02 +01:00
|
|
|
|
2012-06-06 16:58:19 +02:00
|
|
|
int option_index = 0;
|
2014-02-09 10:47:26 +01:00
|
|
|
int c = getopt_long(argc, argv, "DL:b:c:f:hkn:opsv", long_options,
|
2012-06-06 16:58:19 +02:00
|
|
|
&option_index);
|
|
|
|
if(c == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(c) {
|
|
|
|
case 'D':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_DAEMON, "yes");
|
2012-06-06 16:58:19 +02:00
|
|
|
break;
|
|
|
|
case 'L':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_LOG_LEVEL, optarg);
|
2012-06-06 16:58:19 +02:00
|
|
|
break;
|
|
|
|
case 'b':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND, optarg);
|
2012-06-06 16:58:19 +02:00
|
|
|
break;
|
2012-11-22 14:05:52 +01:00
|
|
|
case 'c':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS, optarg);
|
2012-11-22 14:05:52 +01:00
|
|
|
break;
|
2012-06-06 16:58:19 +02:00
|
|
|
case 'f':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND, optarg);
|
2012-06-06 16:58:19 +02:00
|
|
|
break;
|
2012-11-22 14:05:52 +01:00
|
|
|
case 'h':
|
|
|
|
print_help(std::cout);
|
|
|
|
exit(EXIT_SUCCESS);
|
2012-11-22 13:46:15 +01:00
|
|
|
case 'k':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_INSECURE, "yes");
|
2012-11-22 13:46:15 +01:00
|
|
|
break;
|
2012-06-06 16:58:19 +02:00
|
|
|
case 'n':
|
2014-04-23 17:47:26 +02:00
|
|
|
#ifdef NOTHREADS
|
2014-07-05 12:43:39 +02:00
|
|
|
LOG(WARNING) << "Threading disabled at build time, no threads created.";
|
2014-04-23 17:47:26 +02:00
|
|
|
#else
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WORKERS, optarg);
|
2014-05-14 16:22:23 +02:00
|
|
|
#endif // NOTHREADS
|
2012-06-06 16:58:19 +02:00
|
|
|
break;
|
2014-02-09 10:47:26 +01:00
|
|
|
case 'o':
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_FRAME_DEBUG, "yes");
|
|
|
|
break;
|
2012-11-22 14:05:52 +01:00
|
|
|
case 'p':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PROXY, "yes");
|
2012-06-06 16:58:19 +02:00
|
|
|
break;
|
2012-07-11 09:20:16 +02:00
|
|
|
case 's':
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_PROXY, "yes");
|
2012-07-11 09:20:16 +02:00
|
|
|
break;
|
2012-11-22 15:08:36 +01:00
|
|
|
case 'v':
|
|
|
|
print_version(std::cout);
|
|
|
|
exit(EXIT_SUCCESS);
|
2012-06-06 16:58:19 +02:00
|
|
|
case '?':
|
2014-01-08 17:27:56 +01:00
|
|
|
util::show_candidates(argv[optind - 1], long_options);
|
2012-06-06 16:58:19 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2012-07-12 16:39:11 +02:00
|
|
|
case 0:
|
|
|
|
switch(flag) {
|
|
|
|
case 1:
|
|
|
|
// --add-x-forwarded-for
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_ADD_X_FORWARDED_FOR, "yes");
|
2012-07-12 16:39:11 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 2:
|
2013-11-04 10:14:05 +01:00
|
|
|
// --frontend-http2-read-timeout
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT, optarg);
|
2012-07-17 17:13:11 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 3:
|
2012-07-17 17:13:11 +02:00
|
|
|
// --frontend-read-timeout
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_READ_TIMEOUT, optarg);
|
2012-07-17 17:13:11 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 4:
|
2012-07-17 17:13:11 +02:00
|
|
|
// --frontend-write-timeout
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_WRITE_TIMEOUT, optarg);
|
2012-07-17 17:13:11 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 5:
|
2012-07-17 17:13:11 +02:00
|
|
|
// --backend-read-timeout
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_READ_TIMEOUT, optarg);
|
2012-07-17 17:13:11 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 6:
|
2012-07-17 17:13:11 +02:00
|
|
|
// --backend-write-timeout
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_WRITE_TIMEOUT, optarg);
|
2012-07-17 17:13:11 +02:00
|
|
|
break;
|
2012-07-17 18:08:05 +02:00
|
|
|
case 7:
|
2014-07-05 11:22:40 +02:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_FILE, optarg);
|
2012-07-17 18:08:05 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 8:
|
2012-07-26 16:08:51 +02:00
|
|
|
// --backend-keep-alive-timeout
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT, optarg);
|
2012-07-26 16:08:51 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 9:
|
2013-11-04 10:14:05 +01:00
|
|
|
// --frontend-http2-window-bits
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS, optarg);
|
2012-07-26 16:18:37 +02:00
|
|
|
break;
|
2012-07-31 18:51:16 +02:00
|
|
|
case 10:
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_PID_FILE, optarg);
|
2012-07-31 18:51:16 +02:00
|
|
|
break;
|
2012-08-01 17:06:41 +02:00
|
|
|
case 11:
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_USER, optarg);
|
2012-08-01 17:06:41 +02:00
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
// --conf
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->conf_path = strcopy(optarg);
|
2012-07-31 18:51:16 +02:00
|
|
|
break;
|
2012-08-01 18:20:18 +02:00
|
|
|
case 14:
|
|
|
|
// --syslog-facility
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_SYSLOG_FACILITY, optarg);
|
2012-08-01 18:20:18 +02:00
|
|
|
break;
|
2012-08-01 18:28:59 +02:00
|
|
|
case 15:
|
|
|
|
// --backlog
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKLOG, optarg);
|
2012-08-01 18:28:59 +02:00
|
|
|
break;
|
2012-08-20 14:50:03 +02:00
|
|
|
case 16:
|
|
|
|
// --ciphers
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_CIPHERS, optarg);
|
2012-08-20 14:50:03 +02:00
|
|
|
break;
|
2012-11-18 13:23:13 +01:00
|
|
|
case 17:
|
2012-11-21 14:10:35 +01:00
|
|
|
// --client
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_CLIENT, "yes");
|
2012-11-18 13:23:13 +01:00
|
|
|
break;
|
2012-11-21 15:47:48 +01:00
|
|
|
case 18:
|
2013-11-04 10:14:05 +01:00
|
|
|
// --backend-http2-window-bits
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS, optarg);
|
2012-11-21 15:47:48 +01:00
|
|
|
break;
|
2012-11-22 13:46:15 +01:00
|
|
|
case 19:
|
|
|
|
// --cacert
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_CACERT, optarg);
|
2012-11-22 13:46:15 +01:00
|
|
|
break;
|
2012-11-23 13:11:01 +01:00
|
|
|
case 20:
|
|
|
|
// --backend-ipv4
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV4, "yes");
|
2012-11-23 13:11:01 +01:00
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
// --backend-ipv6
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV6, "yes");
|
2012-11-23 13:11:01 +01:00
|
|
|
break;
|
2012-12-03 07:33:04 +01:00
|
|
|
case 22:
|
|
|
|
// --private-key-passwd-file
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE, optarg);
|
2012-12-03 07:33:04 +01:00
|
|
|
break;
|
2013-01-09 14:01:25 +01:00
|
|
|
case 23:
|
|
|
|
// --no-via
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_NO_VIA, "yes");
|
2013-01-09 14:01:25 +01:00
|
|
|
break;
|
2013-02-06 15:27:05 +01:00
|
|
|
case 24:
|
|
|
|
// --subcert
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_SUBCERT, optarg);
|
2013-02-06 15:27:05 +01:00
|
|
|
break;
|
2013-02-08 13:46:58 +01:00
|
|
|
case 25:
|
2013-11-04 10:14:05 +01:00
|
|
|
// --http2-bridge
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_BRIDGE, "yes");
|
2013-02-08 13:46:58 +01:00
|
|
|
break;
|
2013-02-09 08:42:01 +01:00
|
|
|
case 26:
|
|
|
|
// --backend-http-proxy-uri
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP_PROXY_URI, optarg);
|
2013-02-09 08:42:01 +01:00
|
|
|
break;
|
2013-02-22 13:54:07 +01:00
|
|
|
case 27:
|
2013-08-03 11:58:14 +02:00
|
|
|
// --backend-no-tls
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_NO_TLS, "yes");
|
2013-02-22 13:54:07 +01:00
|
|
|
break;
|
2013-03-24 13:03:39 +01:00
|
|
|
case 29:
|
2013-08-03 11:58:14 +02:00
|
|
|
// --frontend-no-tls
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_NO_TLS, "yes");
|
2013-03-24 13:03:39 +01:00
|
|
|
break;
|
2013-03-29 14:06:33 +01:00
|
|
|
case 31:
|
|
|
|
// --backend-tls-sni-field
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_TLS_SNI_FIELD, optarg);
|
2013-03-29 14:06:33 +01:00
|
|
|
break;
|
2013-08-30 15:07:42 +02:00
|
|
|
case 33:
|
|
|
|
// --dh-param-file
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_DH_PARAM_FILE, optarg);
|
2013-08-30 15:07:42 +02:00
|
|
|
break;
|
2014-08-17 09:17:10 +02:00
|
|
|
case 34:
|
|
|
|
// --read-rate
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_READ_RATE, optarg);
|
|
|
|
break;
|
|
|
|
case 35:
|
|
|
|
// --read-burst
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_READ_BURST, optarg);
|
|
|
|
break;
|
|
|
|
case 36:
|
|
|
|
// --write-rate
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WRITE_RATE, optarg);
|
|
|
|
break;
|
|
|
|
case 37:
|
|
|
|
// --write-burst
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WRITE_BURST, optarg);
|
|
|
|
break;
|
2013-09-23 13:55:39 +02:00
|
|
|
case 38:
|
|
|
|
// --npn-list
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_NPN_LIST, optarg);
|
2013-09-23 13:55:39 +02:00
|
|
|
break;
|
2013-11-01 17:10:18 +01:00
|
|
|
case 39:
|
|
|
|
// --verify-client
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT, "yes");
|
2013-11-01 17:10:18 +01:00
|
|
|
break;
|
2013-11-02 13:30:32 +01:00
|
|
|
case 40:
|
|
|
|
// --verify-client-cacert
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT_CACERT, optarg);
|
2013-11-02 13:30:32 +01:00
|
|
|
break;
|
2013-11-02 14:58:02 +01:00
|
|
|
case 41:
|
|
|
|
// --client-private-key-file
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE, optarg);
|
2013-11-02 14:58:02 +01:00
|
|
|
break;
|
|
|
|
case 42:
|
|
|
|
// --client-cert-file
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_CERT_FILE, optarg);
|
2013-11-02 14:58:02 +01:00
|
|
|
break;
|
2013-11-17 15:52:19 +01:00
|
|
|
case 43:
|
|
|
|
// --frontend-http2-dump-request-header
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER,
|
|
|
|
optarg);
|
2013-11-17 15:52:19 +01:00
|
|
|
break;
|
|
|
|
case 44:
|
|
|
|
// --frontend-http2-dump-response-header
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER,
|
|
|
|
optarg);
|
2013-11-17 15:52:19 +01:00
|
|
|
break;
|
2013-11-17 16:03:55 +01:00
|
|
|
case 45:
|
|
|
|
// --http2-no-cookie-crumbling
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING, "yes");
|
2013-11-17 16:03:55 +01:00
|
|
|
break;
|
2013-11-20 16:15:17 +01:00
|
|
|
case 46:
|
|
|
|
// --frontend-http2-connection-window-bits
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS,
|
|
|
|
optarg);
|
2013-11-20 16:15:17 +01:00
|
|
|
break;
|
|
|
|
case 47:
|
|
|
|
// --backend-http2-connection-window-bits
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS,
|
|
|
|
optarg);
|
2013-11-20 16:15:17 +01:00
|
|
|
break;
|
2014-01-02 03:49:38 +01:00
|
|
|
case 48:
|
|
|
|
// --tls-proto-list
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_TLS_PROTO_LIST, optarg);
|
2014-01-02 03:49:38 +01:00
|
|
|
break;
|
2014-02-11 09:23:22 +01:00
|
|
|
case 49:
|
|
|
|
// --padding
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_PADDING, optarg);
|
|
|
|
break;
|
2014-03-09 06:53:28 +01:00
|
|
|
case 50:
|
|
|
|
// --worker-read-rate
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WORKER_READ_RATE, optarg);
|
|
|
|
break;
|
|
|
|
case 51:
|
|
|
|
// --worker-read-burst
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WORKER_READ_BURST, optarg);
|
|
|
|
break;
|
|
|
|
case 52:
|
|
|
|
// --worker-write-rate
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WORKER_WRITE_RATE, optarg);
|
|
|
|
break;
|
|
|
|
case 53:
|
|
|
|
// --worker-write-burst
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WORKER_WRITE_BURST, optarg);
|
|
|
|
break;
|
2014-04-03 06:20:50 +02:00
|
|
|
case 54:
|
2014-04-08 15:28:50 +02:00
|
|
|
// --altsvc
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_ALTSVC, optarg);
|
2014-04-03 06:20:50 +02:00
|
|
|
break;
|
2014-04-26 07:56:08 +02:00
|
|
|
case 55:
|
|
|
|
// --add-response-header
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_ADD_RESPONSE_HEADER, optarg);
|
|
|
|
break;
|
2014-06-26 15:55:22 +02:00
|
|
|
case 56:
|
|
|
|
// --worker-frontend-connections
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS, optarg);
|
|
|
|
break;
|
2014-07-05 11:22:40 +02:00
|
|
|
case 57:
|
|
|
|
// --accesslog-syslog
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_SYSLOG, "yes");
|
|
|
|
break;
|
|
|
|
case 58:
|
|
|
|
// --errorlog-file
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_ERRORLOG_FILE, optarg);
|
|
|
|
break;
|
|
|
|
case 59:
|
|
|
|
// --errorlog-syslog
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_ERRORLOG_SYSLOG, "yes");
|
|
|
|
break;
|
2014-08-09 11:47:45 +02:00
|
|
|
case 60:
|
|
|
|
// --stream-read-timeout
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_STREAM_READ_TIMEOUT, optarg);
|
|
|
|
break;
|
|
|
|
case 61:
|
|
|
|
// --stream-write-timeout
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_STREAM_WRITE_TIMEOUT, optarg);
|
|
|
|
break;
|
2014-08-10 05:39:27 +02:00
|
|
|
case 62:
|
|
|
|
// --no-location-rewrite
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_NO_LOCATION_REWRITE, "yes");
|
|
|
|
break;
|
2014-08-16 14:29:20 +02:00
|
|
|
case 63:
|
|
|
|
// --backend-connections-per-frontend
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_CONNECTIONS_PER_FRONTEND,
|
|
|
|
optarg);
|
|
|
|
break;
|
2012-07-12 16:39:11 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2012-06-06 16:58:19 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-06 15:27:05 +01:00
|
|
|
// Initialize OpenSSL before parsing options because we create
|
|
|
|
// SSL_CTX there.
|
2014-08-02 03:11:45 +02:00
|
|
|
OPENSSL_config(nullptr);
|
2013-02-06 15:27:05 +01:00
|
|
|
OpenSSL_add_all_algorithms();
|
|
|
|
SSL_load_error_strings();
|
|
|
|
SSL_library_init();
|
2014-04-23 17:47:26 +02:00
|
|
|
#ifndef NOTHREADS
|
2014-03-04 13:33:43 +01:00
|
|
|
nghttp2::ssl::LibsslGlobalLock();
|
2014-05-14 16:22:23 +02:00
|
|
|
#endif // NOTHREADS
|
2013-02-06 15:27:05 +01:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
if(conf_exists(get_config()->conf_path.get())) {
|
|
|
|
if(load_config(get_config()->conf_path.get()) == -1) {
|
2012-08-01 17:26:24 +02:00
|
|
|
LOG(FATAL) << "Failed to load configuration from "
|
2014-06-08 14:02:40 +02:00
|
|
|
<< get_config()->conf_path.get();
|
2012-08-01 17:06:41 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc - optind >= 2) {
|
2014-01-18 08:32:22 +01:00
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_FILE, argv[optind++]);
|
|
|
|
cmdcfgs.emplace_back(SHRPX_OPT_CERTIFICATE_FILE, argv[optind++]);
|
2012-08-01 17:06:41 +02:00
|
|
|
}
|
2012-06-06 17:03:05 +02:00
|
|
|
|
2014-08-17 15:37:30 +02:00
|
|
|
// First open default log files to deal with errors occurred while
|
|
|
|
// parsing option values.
|
|
|
|
reopen_log_files();
|
|
|
|
|
2012-08-01 17:06:41 +02:00
|
|
|
for(size_t i = 0, len = cmdcfgs.size(); i < len; ++i) {
|
|
|
|
if(parse_config(cmdcfgs[i].first, cmdcfgs[i].second) == -1) {
|
2012-08-01 17:26:24 +02:00
|
|
|
LOG(FATAL) << "Failed to parse command-line argument.";
|
2012-08-01 17:06:41 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2012-06-06 17:03:05 +02:00
|
|
|
|
2014-07-05 11:22:40 +02:00
|
|
|
if(get_config()->accesslog_syslog || get_config()->errorlog_syslog) {
|
2014-06-12 14:46:25 +02:00
|
|
|
openlog("nghttpx", LOG_NDELAY | LOG_NOWAIT | LOG_PID,
|
|
|
|
get_config()->syslog_facility);
|
2014-07-05 11:22:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(reopen_log_files() != 0) {
|
|
|
|
LOG(FATAL) << "Failed to open log file";
|
|
|
|
exit(EXIT_FAILURE);
|
2014-06-12 14:46:25 +02:00
|
|
|
}
|
|
|
|
|
2014-08-10 13:58:02 +02:00
|
|
|
if(get_config()->uid != 0) {
|
2014-08-19 14:33:54 +02:00
|
|
|
if(worker_config->accesslog_fd != -1 &&
|
|
|
|
fchown(worker_config->accesslog_fd,
|
2014-08-10 13:58:02 +02:00
|
|
|
get_config()->uid, get_config()->gid) == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(WARNING) << "Changing owner of access log file failed: "
|
|
|
|
<< strerror(error);
|
|
|
|
}
|
2014-08-19 14:33:54 +02:00
|
|
|
if(worker_config->errorlog_fd != -1 &&
|
|
|
|
fchown(worker_config->errorlog_fd,
|
2014-08-10 13:58:02 +02:00
|
|
|
get_config()->uid, get_config()->gid) == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(WARNING) << "Changing owner of error log file failed: "
|
|
|
|
<< strerror(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 18:53:44 +02:00
|
|
|
if(get_config()->http2_upstream_dump_request_header_file) {
|
|
|
|
auto path = get_config()->http2_upstream_dump_request_header_file.get();
|
|
|
|
auto f = open_file_for_write(path);
|
|
|
|
|
|
|
|
if(f == nullptr) {
|
|
|
|
LOG(FATAL) << "Failed to open http2 upstream request header file: "
|
|
|
|
<< path;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_config()->http2_upstream_dump_request_header = f;
|
|
|
|
|
|
|
|
if(get_config()->uid != 0) {
|
|
|
|
if(chown(path, get_config()->uid, get_config()->gid) == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(WARNING) << "Changing owner of http2 upstream request header file "
|
|
|
|
<< path
|
|
|
|
<< " failed: "
|
|
|
|
<< strerror(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(get_config()->http2_upstream_dump_response_header_file) {
|
|
|
|
auto path = get_config()->http2_upstream_dump_response_header_file.get();
|
|
|
|
auto f = open_file_for_write(path);
|
|
|
|
|
|
|
|
if(f == nullptr) {
|
|
|
|
LOG(FATAL) << "Failed to open http2 upstream response header file: "
|
|
|
|
<< path;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_config()->http2_upstream_dump_response_header = f;
|
|
|
|
|
|
|
|
if(get_config()->uid != 0) {
|
|
|
|
if(chown(path, get_config()->uid, get_config()->gid) == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(WARNING) << "Changing owner of http2 upstream response header file"
|
|
|
|
<< " "
|
|
|
|
<< path
|
|
|
|
<< " failed: "
|
|
|
|
<< strerror(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 15:52:27 +02:00
|
|
|
if(get_config()->npn_list.empty()) {
|
|
|
|
mod_config()->npn_list = parse_config_str_list(DEFAULT_NPN_LIST);
|
2013-09-23 13:55:39 +02:00
|
|
|
}
|
2014-06-08 15:52:27 +02:00
|
|
|
if(get_config()->tls_proto_list.empty()) {
|
2014-01-02 03:49:38 +01:00
|
|
|
mod_config()->tls_proto_list = parse_config_str_list
|
2014-06-08 15:52:27 +02:00
|
|
|
(DEFAULT_TLS_PROTO_LIST);
|
2014-01-02 03:49:38 +01:00
|
|
|
}
|
2013-09-23 13:55:39 +02:00
|
|
|
|
2014-06-08 15:52:27 +02:00
|
|
|
mod_config()->tls_proto_mask =
|
|
|
|
ssl::create_tls_proto_mask(get_config()->tls_proto_list);
|
|
|
|
|
2014-06-10 16:15:29 +02:00
|
|
|
mod_config()->alpn_prefs = ssl::set_alpn_prefs(get_config()->npn_list);
|
|
|
|
|
2013-11-01 17:10:18 +01:00
|
|
|
if(!get_config()->subcerts.empty()) {
|
|
|
|
mod_config()->cert_tree = ssl::cert_lookup_tree_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto& keycert : get_config()->subcerts) {
|
|
|
|
auto ssl_ctx = ssl::create_ssl_context(keycert.first.c_str(),
|
|
|
|
keycert.second.c_str());
|
|
|
|
if(ssl::cert_lookup_tree_add_cert_from_file
|
|
|
|
(get_config()->cert_tree, ssl_ctx, keycert.second.c_str()) == -1) {
|
|
|
|
LOG(FATAL) << "Failed to add sub certificate.";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 16:17:46 +02:00
|
|
|
if(get_config()->cert_file && get_config()->private_key_file) {
|
|
|
|
mod_config()->default_ssl_ctx =
|
2014-06-08 14:02:40 +02:00
|
|
|
ssl::create_ssl_context(get_config()->private_key_file.get(),
|
|
|
|
get_config()->cert_file.get());
|
2013-06-21 16:17:46 +02:00
|
|
|
if(get_config()->cert_tree) {
|
2014-06-08 14:02:40 +02:00
|
|
|
if(ssl::cert_lookup_tree_add_cert_from_file
|
|
|
|
(get_config()->cert_tree,
|
|
|
|
get_config()->default_ssl_ctx,
|
|
|
|
get_config()->cert_file.get()) == -1) {
|
2013-06-21 16:17:46 +02:00
|
|
|
LOG(FATAL) << "Failed to parse command-line argument.";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-23 13:11:01 +01:00
|
|
|
if(get_config()->backend_ipv4 && get_config()->backend_ipv6) {
|
|
|
|
LOG(FATAL) << "--backend-ipv4 and --backend-ipv6 cannot be used at the "
|
|
|
|
<< "same time.";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:55:22 +02:00
|
|
|
if(get_config()->worker_frontend_connections == 0) {
|
|
|
|
mod_config()->worker_frontend_connections =
|
|
|
|
std::numeric_limits<size_t>::max();
|
|
|
|
}
|
|
|
|
|
2013-11-04 10:14:05 +01:00
|
|
|
if(get_config()->http2_proxy + get_config()->http2_bridge +
|
2013-02-08 13:46:58 +01:00
|
|
|
get_config()->client_proxy + get_config()->client > 1) {
|
2013-11-04 10:14:05 +01:00
|
|
|
LOG(FATAL) << "--http2-proxy, --http2-bridge, --client-proxy and --client "
|
2013-02-08 13:46:58 +01:00
|
|
|
<< "cannot be used at the same time.";
|
2012-11-21 14:10:35 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(get_config()->client || get_config()->client_proxy) {
|
|
|
|
mod_config()->client_mode = true;
|
|
|
|
}
|
|
|
|
|
2013-11-04 10:14:05 +01:00
|
|
|
if(get_config()->client_mode || get_config()->http2_bridge) {
|
2013-11-04 10:15:56 +01:00
|
|
|
mod_config()->downstream_proto = PROTO_HTTP2;
|
2013-02-22 13:54:07 +01:00
|
|
|
} else {
|
|
|
|
mod_config()->downstream_proto = PROTO_HTTP;
|
|
|
|
}
|
|
|
|
|
2013-08-03 12:01:57 +02:00
|
|
|
if(!get_config()->client_mode && !get_config()->upstream_no_tls) {
|
2012-11-18 13:23:13 +01:00
|
|
|
if(!get_config()->private_key_file || !get_config()->cert_file) {
|
|
|
|
print_usage(std::cerr);
|
|
|
|
LOG(FATAL) << "Too few arguments";
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-14 16:01:47 +02:00
|
|
|
bool downstream_ipv6_addr =
|
2014-06-08 14:02:40 +02:00
|
|
|
is_ipv6_numeric_addr(get_config()->downstream_host.get());
|
2014-05-14 15:39:28 +02:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
{
|
|
|
|
std::string hostport;
|
2014-05-14 15:39:28 +02:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
if(downstream_ipv6_addr) {
|
|
|
|
hostport += "[";
|
|
|
|
}
|
2014-05-14 15:39:28 +02:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
hostport += get_config()->downstream_host.get();
|
2014-05-14 15:39:28 +02:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
if(downstream_ipv6_addr) {
|
|
|
|
hostport += "]";
|
|
|
|
}
|
2014-05-14 15:39:28 +02:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
hostport += ":";
|
|
|
|
hostport += util::utos(get_config()->downstream_port);
|
2014-05-14 15:39:28 +02:00
|
|
|
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->downstream_hostport = strcopy(hostport);
|
|
|
|
}
|
2012-06-06 16:58:19 +02:00
|
|
|
|
2013-02-09 08:42:01 +01:00
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Resolving backend address";
|
|
|
|
}
|
|
|
|
if(resolve_hostname(&mod_config()->downstream_addr,
|
|
|
|
&mod_config()->downstream_addrlen,
|
2014-06-08 14:02:40 +02:00
|
|
|
get_config()->downstream_host.get(),
|
2013-02-09 08:42:01 +01:00
|
|
|
get_config()->downstream_port,
|
|
|
|
get_config()->backend_ipv4 ? AF_INET :
|
|
|
|
(get_config()->backend_ipv6 ?
|
|
|
|
AF_INET6 : AF_UNSPEC)) == -1) {
|
2012-06-04 16:48:31 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2012-06-05 18:26:04 +02:00
|
|
|
|
2013-02-09 08:42:01 +01:00
|
|
|
if(get_config()->downstream_http_proxy_host) {
|
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Resolving backend http proxy address";
|
|
|
|
}
|
|
|
|
if(resolve_hostname(&mod_config()->downstream_http_proxy_addr,
|
|
|
|
&mod_config()->downstream_http_proxy_addrlen,
|
2014-06-08 14:02:40 +02:00
|
|
|
get_config()->downstream_http_proxy_host.get(),
|
2013-02-09 08:42:01 +01:00
|
|
|
get_config()->downstream_http_proxy_port,
|
|
|
|
AF_UNSPEC) == -1) {
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 09:17:10 +02:00
|
|
|
mod_config()->rate_limit_cfg = ev_token_bucket_cfg_new
|
|
|
|
(get_rate_limit(get_config()->read_rate),
|
|
|
|
get_rate_limit(get_config()->read_burst),
|
|
|
|
get_rate_limit(get_config()->write_rate),
|
|
|
|
get_rate_limit(get_config()->write_burst),
|
|
|
|
nullptr);
|
|
|
|
|
2014-03-09 06:53:28 +01:00
|
|
|
mod_config()->worker_rate_limit_cfg = ev_token_bucket_cfg_new
|
|
|
|
(get_rate_limit(get_config()->worker_read_rate),
|
|
|
|
get_rate_limit(get_config()->worker_read_burst),
|
|
|
|
get_rate_limit(get_config()->worker_write_rate),
|
|
|
|
get_rate_limit(get_config()->worker_write_burst),
|
|
|
|
nullptr);
|
|
|
|
|
2014-02-09 10:47:26 +01:00
|
|
|
if(get_config()->upstream_frame_debug) {
|
|
|
|
// To make it sync to logging
|
|
|
|
set_output(stderr);
|
|
|
|
if(isatty(fileno(stdout))) {
|
|
|
|
set_color_output(true);
|
|
|
|
}
|
|
|
|
reset_timer();
|
|
|
|
}
|
|
|
|
|
2012-06-06 16:58:19 +02:00
|
|
|
struct sigaction act;
|
|
|
|
memset(&act, 0, sizeof(struct sigaction));
|
|
|
|
act.sa_handler = SIG_IGN;
|
2014-08-16 17:05:24 +02:00
|
|
|
sigaction(SIGPIPE, &act, nullptr);
|
|
|
|
sigaction(SIGCHLD, &act, nullptr);
|
2012-06-06 16:58:19 +02:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
event_loop();
|
2012-06-08 15:41:24 +02:00
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
if(LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Shutdown momentarily";
|
|
|
|
}
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace shrpx
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
return shrpx::main(argc, argv);
|
|
|
|
}
|