Lighttpd リバースプロキシ

Lighttpd リバースプロキシ

2 つの Raspberry Pi サーバーが稼働しています。これはDietPiを使用して設定されます。あるサーバーはNextCloudサーバーとして機能します。別の(新しい)サーバーがweewxを実行しています。どちらもlighttpdをWebサーバーとして使用します。各ドメインは、異なるドメインmy.domain.comとmy.otherdomain.comで実行されます。

私のルーターには1つのIPアドレスがあり、ポート転送を使用して両方のサーバーにアクセスします。 NextCloudサーバー(my.domain.com)では、Dietpi-letsencryptを使用してSSLが有効になっています。パブリックIPアドレスしかないため、my.otherdomain.comでcertbotを実行できません。

Nextcloudシステム(my.domain.com)でmod-proxyを有効にし、my.otherdomain.comへの要求をweewxシステムに転送します。ルータからweewxシステムへのポート転送を無効にしました。ただし、Dietpi-letsencryptはweewxシステムのSSL証明書を生成できません。チャレンジが失敗しました。 2台のコンピュータでcertbotを実行しようとしています。私のNextcloudシステム(私のプロキシサーバーとして使用されます)の試みは次のとおりです。

Do you want to expand and replace this existing certificate with the new
certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(E)xpand/(C)ancel: E 
Renewing an existing certificate for my.domain.com and my.otherdomain.com
Performing the following challenges:
http-01 challenge for aws.andrewterhorst.com
Using the webroot path /var/www for all unmatched domains.
Waiting for verification...
Challenge failed for domain my.otherdomain.com
http-01 challenge for my.otherdomain.com
Cleaning up challenges
Some challenges have failed.

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: my.otherdomain.com
   Type:   unauthorized
   Detail: Invalid response from
   http://my.otherdomain.com/.well-known/acme-challenge/p16SmhyufIGQ75fnhWQ4zxf49TCLfnX4SoWRmBqAHBg
   [129.151.176.124]: "<?xml version=\"1.0\"
   encoding=\"iso-8859-1\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD
   XHTML 1.0 Transitional//EN\"\n         \"http://www."

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.
[FAILED] DietPi-LetsEncrypt | Certbot failed, please check its above terminal output. Aborting...

私のリバースプロキシ設定が間違っているようです。インターネットで回答を検索するのは難しかった。これはNextcloudシステムの/etc/lighttpd/lighttpd.confファイルです。

server.modules = (
    "mod_indexfile",
    "mod_setenv",
    "mod_access",
    "mod_alias",
    "mod_redirect",
    "mod_proxy",
)

server.document-root = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80

# features
#https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_feature-flagsDetails
server.feature-flags       += ("server.h2proto" => "enable")
server.feature-flags       += ("server.h2c"     => "enable")
server.feature-flags       += ("server.graceful-shutdown-timeout" => 5)
#server.feature-flags       += ("server.graceful-restart-bg" => "enable")

# strict parsing and normalization of URL for consistency and security
# https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_http-parseoptsDetails
# (might need to explicitly set "url-path-2f-decode" = "disable"
#  if a specific application is encoding URLs inside url-path)
server.http-parseopts = (
  "header-strict"           => "enable",# default
  "host-strict"             => "enable",# default
  "host-normalize"          => "enable",# default
  "url-normalize-unreserved"=> "enable",# recommended highly
  "url-normalize-required"  => "enable",# recommended
  "url-ctrls-reject"        => "enable",# recommended
  "url-path-2f-decode"      => "enable",# recommended highly (unless breaks app)
 #"url-path-2f-reject"      => "enable",
  "url-path-dotseg-remove"  => "enable",# recommended highly (unless breaks app)
 #"url-path-dotseg-reject"  => "enable",
 #"url-query-20-plus"       => "enable",# consistency in query string
)

index-file.names            = ( "index.php", "index.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.conf.pl"
include "/etc/lighttpd/conf-enabled/*.conf"

#server.compat-module-load   = "disable"
server.modules += (
    "mod_dirlisting",
    "mod_staticfile",
)


# proxy settings
$HTTP["host"]=~ "my.otherdomain.com"  {
        proxy.balance = "fair"
        proxy.server =  ("" =>
                                (
                                        ( "host" => "192.168.0.261", "port" => 80 ),
                                        ( "host" => "192.168.0.261", "port" => 443 )
                                ))
                        }

技術的には、プロキシ設定は10-proxy.confになければなりません。次のコマンドを実行する必要があります。

lighty-enable-mod proxy

これにより、/etc/lighttpd/conf-availableの10-proxy.confへの/etc/lighttpd/conf-enabledのシンボリックリンクが生成されます。 lighttpd.confにプロキシ設定を追加すればよいという内容を読みました。 10-proxy.confを使用する必要はありません。

現在の設定とは、my.otherdomain.com への着信トラフィックが最終的に 2 番目の weewx コンピュータに到達することを意味します。しかし、certbotは通信が必要です。 weewxシステムとNextCloudシステムのどちらでcertbotを実行する必要があるのか​​混乱しています。

私はLinuxの専門家ではなく、weewxシステムが安全であるように、順方向および逆方向のプロキシに対してlighttpdを設定する方法についての指示が必要です。これをカバーするほとんどの投稿には、Apache、nginx、またはいくつかの特定のWebアプリケーション設定が含まれます。 lighttpd conf設定の構文は正規表現のような表記法を使用するので、非常に混乱しています。たとえば、

$HTTP['host'] =~ '^(www.example.com)$' {
        url.rewrite-once = ('^/(.*)' => '/vhost/http/%0/$1')
        # In lighttpd we alter the path manually using rewrite rule. %0
        # refers to the hostname and $1 is the path.
        proxy.server = ( '' =>
                ( (
                'host' => '127.0.0.1',
                'port' => 8080
                ) )
        )
}

私のような愚か者には、英語で簡単なステップバイステップのチュートリアルはありません。

答え1

私は問題を避けることで問題を解決しました。ここでは、3番目のRaspberry Piをnginxプロキシマネージャ(https://nginxproxymanager.com/)。ここで説明した設定を使用しました。https://www.gitmemory.com/issue/MichaIng/DietPi/4417/847424141

基本的に私が従ったステップは次のとおりです。

  1. Dietpiを実行する新しいRaspberry Piの設定
  2. Dietpiソフトウェアメニューからdockerとdocker composeをインストールします。
  3. Nginxディレクトリの作成
  4. 次のコンテンツでこのディレクトリにdocker-compose.ymlフォルダを作成します。
version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:2'
    restart: always
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
      # Add any other Stream port you want to expose
      # - '21:21' # FTP
    environment:
      # If you would rather use Sqlite uncomment this
      # and remove all DB_MYSQL_* lines above
      DB_SQLITE_FILE: "/data/database.sqlite"
      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
  1. sqliteデータベースを作成します。
touch ./data/database.sqlite.
  1. 次のコマンドを使用してnginxプロキシマネージャを設定します。
docker-compose up -d
  1. Raspberry PiとViolaを再起動しました。箱から取り出してすぐに働きました!

  2. それからhttp://proxyserver_ip:81で管理インターフェイスにログインしました。清潔でモダンなインターフェースです。次に、nextcloudとweewxを実行している2つのサーバーにポート転送を追加しました。 nginxプロキシ管理者はLetsencryptを介してSSL証明書を取得します。すべてのサーバーにインストールする必要はありません。プロキシ転送はポート80を使用しますが、管理インターフェイスのSSLタブでhttpsを強制的に使用できます。

  3. httpsを有効にした後、nextcloudサーバーで小さな問題(502 Bad Gateway)が発生しました。 nextcloud config.php ファイルに次の行を追加する必要があります。

'overwriteprotocol' => 'https',
  1. すべてがいつものように甘いです!

関連情報