http2-server.pl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. #***************************************************************************
  25. # This script invokes nghttpx properly to have it serve HTTP/2 for us.
  26. # nghttpx runs as a proxy in front of our "actual" HTTP/1 server.
  27. use Cwd;
  28. use Cwd 'abs_path';
  29. use File::Basename;
  30. my $pidfile = "log/nghttpx.pid";
  31. my $logfile = "log/http2.log";
  32. my $nghttpx = "nghttpx";
  33. my $listenport = 9015;
  34. my $listenport2 = 9016;
  35. my $connect = "127.0.0.1,8990";
  36. my $conf = "nghttpx.conf";
  37. my $cert = "Server-localhost-sv";
  38. #***************************************************************************
  39. # Process command line options
  40. #
  41. while(@ARGV) {
  42. if($ARGV[0] eq '--verbose') {
  43. $verbose = 1;
  44. }
  45. elsif($ARGV[0] eq '--pidfile') {
  46. if($ARGV[1]) {
  47. $pidfile = $ARGV[1];
  48. shift @ARGV;
  49. }
  50. }
  51. elsif($ARGV[0] eq '--nghttpx') {
  52. if($ARGV[1]) {
  53. $nghttpx = $ARGV[1];
  54. shift @ARGV;
  55. }
  56. }
  57. elsif($ARGV[0] eq '--port') {
  58. if($ARGV[1]) {
  59. $listenport = $ARGV[1];
  60. shift @ARGV;
  61. }
  62. }
  63. elsif($ARGV[0] eq '--port2') {
  64. if($ARGV[1]) {
  65. $listenport2 = $ARGV[1];
  66. shift @ARGV;
  67. }
  68. }
  69. elsif($ARGV[0] eq '--connect') {
  70. if($ARGV[1]) {
  71. $connect = $ARGV[1];
  72. $connect =~ s/:/,/;
  73. shift @ARGV;
  74. }
  75. }
  76. elsif($ARGV[0] eq '--logfile') {
  77. if($ARGV[1]) {
  78. $logfile = $ARGV[1];
  79. shift @ARGV;
  80. }
  81. }
  82. elsif($ARGV[0] eq '--conf') {
  83. if($ARGV[1]) {
  84. $conf = $ARGV[1];
  85. shift @ARGV;
  86. }
  87. }
  88. else {
  89. print STDERR "\nWarning: http2-server.pl unknown parameter: $ARGV[0]\n";
  90. }
  91. shift @ARGV;
  92. }
  93. my $srcdir = dirname(__FILE__);
  94. $certfile = "$srcdir/certs/$cert.pem";
  95. $keyfile = "$srcdir/certs/$cert.key";
  96. $certfile = abs_path($certfile);
  97. $keyfile = abs_path($keyfile);
  98. my $cmdline="$nghttpx --backend=$connect ".
  99. "--frontend=\"*,$listenport;no-tls\" ".
  100. "--frontend=\"*,$listenport2\" ".
  101. "--log-level=INFO ".
  102. "--pid-file=$pidfile ".
  103. "--conf=$conf ".
  104. "--errorlog-file=$logfile ".
  105. "$keyfile $certfile";
  106. print "RUN: $cmdline\n" if($verbose);
  107. system("$cmdline 2>/dev/null");