Overview
このガイドでは、SOCKS 5プロキシを使用して MongoDB に接続する方法を学習できます。 SOCKS 5は、プロキシ サーバーを介してネットワーク サービスで通信するための標準化プロトコルです。
Tip
SOCKS5プロトコルの詳細については、 Wikipedia の SOCKS に関するエントリを参照してください。
SOCKS 5プロキシ設定
プロキシ設定では、SOCKS5 プロキシサーバーのアドレスと認証情報を指定します。これらの設定は、次の方法で指定できます。
これらはパラメーターとして接続 URI に含めます。
MongoClientSettingsインスタンスで、Socks5ProxySettingsプロパティをSocks5ProxySettingsクラスのインスタンスに設定します。
次の表では、SOCKS5 プロキシ設定について説明します。
設定 | 説明 |
|---|---|
Host | Specifies the SOCKS5 proxy IPv4 address, IPv6 address, or hostname.
You must provide this value to connect to a SOCKS5 proxy. |
ポート | Specifies the TCP port number of the SOCKS5 proxy server. Default: 1080 |
認証 | Specifies the authentication settings the SOCKS5 proxy server.
You can use the UsernamePassword() method of the Socks5AuthenticationSettings
class to create authentication settings with your credentials. |
例
次の例は、SOCKS5 プロキシを使用してMongoDBデプロイに接続する方法を示しています。
var settings = new MongoClientSettings.FromConnectionString("<connection URI>"); var proxySettings = new Socks5ProxySettings( "<proxy host>", 1, Socks5AuthenticationSettings.UsernamePassword("<username>", "<password>")); settings.Socks5ProxySettings = proxySettings; var client = new MongoClient(settings);
var connectionURI = "mongodb://localhost:27017/" + "?proxyHost=<proxyHost>" + "&proxyPort=<proxyPort>" + "&proxyUsername=<proxyUsername>" + "&proxyPassword=<proxyPassword>"; var client = new MongoClient(connectionURI);
API ドキュメント
このガイドで説明するメソッドとタイプの詳細については、次の API ドキュメントを参照してください。