
別のサーバーと外部ポート 80 および 443 を共有する Django Web アプリがあります。localhost
リバース プロキシがなくても正常に動作しますが、有効にすると、さまざまなエラーが発生します。
リバースプロキシを適切に動作させるにはどうすればよいですか?
リバースプロキシ.conf:
# SSL Certificate and other SSL configurations
SSLProxyEngine on
ProxyRequests on
SSLProxyVerify require
SSLProxyCheckPeerCN on
SSLProxyCheckPeerName on
SSLProxyCheckPeerExpire on
ProxyPreserveHost on
RequestHeader set X-Forwarded-Proto https
# Reverse Proxy Configuration
ProxyPass "/" "https://192.168.1.83/"
ProxyPassReverse "/" "https://192.168.1.83/"
# Additional SSL configurations if needed
http
私はすべてをリダイレクトしhttps
、上記のプロキシをssl-https confファイルに含めました。サイトは正常に動作しますそれなしインクルード(つまり、Include .../reverse-proxy.conf
コメントアウトされている場合)。リバース プロキシがインクルードされている場合、次のようになります。
[Thu Jan 18 07:09:39.835368 2024] [ssl:error] [pid 46505:tid 133251102926528] [remote 192.168.1.83:443] AH02039: Certificate Verification: Error (20): unable to get local issuer certificate
[Thu Jan 18 07:09:39.835470 2024] [ssl:error] [pid 46505:tid 133251102926528] [remote 192.168.1.83:443] AH02040: Certificate Verification: Certificate Chain too long (chain has 2 certificates, but maximum allowed are only 1)
[Thu Jan 18 07:09:39.835773 2024] [proxy:error] [pid 46505:tid 133251102926528] (20014)Internal error (specific information not available): [client 119.74.38.81:51224] AH01084: pass request body failed to 192.168.1.83:443 (192.168.1.83), referer: https://acupunctureclassique.duckdns.org/
[Thu Jan 18 07:09:39.835832 2024] [proxy:error] [pid 46505:tid 133251102926528] [client 119.74.38.81:51224] AH00898: Error during SSL Handshake with remote server returned by /login/, referer: https://acupunctureclassique.duckdns.org/
[Thu Jan 18 07:09:39.835861 2024] [proxy_http:error] [pid 46505:tid 133251102926528] [client 119.74.38.81:51224] AH01097: pass request body failed to 192.168.1.83:443 (192.168.1.83) from 119.74.38.81 (), referer: https://acupunctureclassique.duckdns.org/
フロントエンド:
Proxy Error
The proxy server could not handle the request
Reason: Error during SSL Handshake with remote server
Apache/2.4.58 (Ubuntu) Server at acupunctureclassique.duckdns.org Port 443
アップデート:
apachectl -S
VirtualHost configuration:
*:443 acupunctureclassique.duckdns.org (/etc/apache2/sites-enabled/acu-le-ssl.conf:2)
*:80 acupunctureclassique.duckdns.org (/etc/apache2/sites-enabled/acu.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
答え1
ここでの実際の問題は、チャットでの議論の後、ユーザーが nginx を使用してトラフィックを同じ nginx インスタンスにプロキシし、巧妙なリダイレクト ループを作成し、最終的にヘッダーが大きすぎるというエラー メッセージにつながっていたことが判明しました。
トラフィックを に送信しますhttps://192.168.1.83
。これはLet's Encryptによって発行された証明書であると主張しますが、LEは一度もないの証明書を発行する192.168.1.83
ことはなく、また、どの公的CAもそのような証明書を発行しません。有効証明書だけでは不十分です。もっている予想される名前(この場合は )と一致させます192.168.1.83
。ログにもこれについてかなり明確に記載されています。
いくつかの選択肢があります:
- HTTPを使用する
- 自己署名証明書を使用し、Apacheがそれを信頼するようにする
SSLProxyCACertificate
指令。 - 有効なドメイン名を使用し、ドメイン名の有効な証明書を取得します。ドメイン名は に解決される
192.168.1.83
か、 に追加される可能性があります/etc/hosts
が、Apache意思証明書内のホスト名と共通名 (または SAN) を一致させます。 - 無効にする名前の確認
SSLProxyCheckPeerName = off
検証を無効にするSSLProxyVerify = none
、検証を事実上無効にします。これは、http を使用することとほぼ同等です...
答え2
リバースプロキシを行うには、/etc/apache2/sites-availableに仮想ホストを作成する必要があります。以下はそのようなVirtualHost設定の例です。
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /path/to/your/django/static/files
Alias /static/ /path/to/your/django/static/files/
<Directory /path/to/your/django/static/files>
Require all granted
</Directory>
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /path/to/your/django/static/files
Alias /static/ /path/to/your/django/static/files/
<Directory /path/to/your/django/static/files>
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /path/to/your/ssl/certificate.crt
SSLCertificateKeyFile /path/to/your/ssl/private.key
SSLCertificateChainFile /path/to/your/ssl/chainfile.pem
ProxyPass / https://localhost:8000/
ProxyPassReverse / https://localhost:8000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
https部分はオプションです。httpsが必要ない場合は省略できます。