SSL を使用して nginx の内側にある Bitbucket Server を保護する

このページでは、nginx サーバーが Bitbucket Server のリバース プロキシとして動作するネットワーク トポロジを確立する方法を説明します。一般に、このような構成は、Bitbucket Server が保護対象のゾーンである "ファイアウォールの内側" にインストールされ、ファイアウォール外のユーザーが Bitbucket Server にアクセスする際に経由するゲートウェイを nginx が提供している場合に使用されます。

このページに記載されている構成は、次のシナリオの結果を示しています。

  • nginx と外部クライアントとの接続が SSL で保護されている。nginx と Bitbucket Server との間の接続が保護されていない。
  • Bitbucket Server と nginx が同じマシン上で実行されている。
  • Bitbucket Server は https://mycompany.com:7990/bitbucket で入手できます。

On this page

また、次の点にも留意してください。

  • すでに実行中の nginx インスタンスが存在することを想定しています。nginx が実行されていない場合、nginx のダウンロードやインストールについて nginx のドキュメントをご確認ください。
  • サーバー マシンに SSL 証明書がインストールされている必要があります。
  • 他のアプリケーションとの既存のリンクは、Bitbucket Server の新しい URL を使用して再構成する必要があります。
  • ユーザーのコンピューターと Bitbucket Server との間の Git 操作の保護は別途検討する必要があります。「Git への SSH アクセスを有効にする」を参照してください。

Bitbucket Server は Web リクエストを直接処理できるため、Web サーバーの背後で実行する必要はありません。この方法で実行する際に Bitbucket Server を保護するには、「SSL を使用して Tomcat で Bitbucket Server を保護する」を参照してください。この方法を行っておらず、nginx が組み込まれた環境に Bitbucket Server をインストールしたい場合は、このドキュメントが最適です (もちろん、SSL を使用して nginx へのクライアント接続を保護することなく、nginx の背後で Bitbucket Server を実行することもできます。このページではこのオプションについては説明しません)。

Note that the Atlassian Support Offering does not cover nginx integration. Assistance with nginx may be obtained through the Atlassian community or from an Atlassian Partner.

ステップ 1: 組み込みの Tomcat コネクタを設定する

Find the Bitbucket configuration properties file <Bitbucket home directory>/shared/bitbucket.properties, creating it if necessary and add the properties as shown below. Instead of mycompany.com, set the server.proxy-name property to your domain name that the nginx server will be configured to serve. This informs Bitbucket Server of the domain name and port of the requests that reach it via nginx, and is important for the correct operation of the Bitbucket Server functions that construct URLs.

server.port=7990
server.secure=true
server.scheme=https
server.proxy-port=443
server.proxy-name=mycompany.com
 

ステップ 2: Bitbucket Server のコンテキスト パスを設定する

デフォルトでは、Bitbucket Server は空のコンテキスト パスで (サーバーの名前空間の "root" から) 実行するよう設定されています。デフォルトの設定では、Bitbucket Server には次の場所でアクセスできます。

http://mycompany.com:7990/

このページの設定例では、Bitbucket Server を次の URL からアクセスできるようにしたいとします。 

https://mycompany.com/bitbucket

In Bitbucket's configuration properties file  <Bitbucket home directory>/shared/bitbucket.properties file, set the context path to /Bitbucket by adding the following property:

server.context-path=/bitbucket

コンテキスト パスを使用する場合、同じパスが次のように使われていることが重要です。

  • Bitbucket Server のベース URL のコンテキスト パスに適用 (ステップ 3)。
  • used when setting up the location for the proxy_pass directive (Step 4). 

ステップ 3: Bitbucket Server のベース URL の変更

Bitbucket Server を再起動する前に、ブラウザ ウィンドウを開き、管理者アカウントを使用して Bitbucket Server にログインします。Bitbucket Server の管理領域に移動し、[設定] 配下の [サーバー設定] をクリックし、[ベース URL] を変更してプロキシ URL (nginx サーバーがサービスを提供する URL) と一致させます。

For this example, use  http://mycompany.com/bitbucket (Note the context path included with this).

ステップ 4: NGINX の構成

Edit /etc/nginx/nginx.conf , using the example server configuration below, to configure nginx as a proxy server. 

Put the proxy_pass directive in the location block, and specify the protocol, name and port of the proxied server in the parameter (in our case, it is http://localhost:7990):

https://confluence.atlassian.com/bitbucketserverkb/git-push-fails-client-intended-to-send-too-large-chunked-body-779171802.html

http {
...
...
	client_max_body_size 0;
...
...
	server {
		listen          443;
    	server_name     mycompany.com;
	
		ssl                  	on;
    	ssl_certificate      	<path/to/your/certificate>;
	    ssl_certificate_key  	<path/to/your/certificate/key>;
	    ssl_session_timeout  	5m;
	    ssl_protocols  			TLSv1 TLSv1.1 TLSv1.2;
	    ssl_ciphers  			HIGH:!aNULL:!MD5;
	    ssl_prefer_server_ciphers   on;
	
		# Optional optimisation - please refer to 
		# http://nginx.org/en/docs/http/configuring_https_servers.html
		# ssl_session_cache   shared:SSL:10m;
	    location /bitbucket {
	        proxy_pass 			http://localhost:7990;
			proxy_set_header 	X-Forwarded-Host $host;
	        proxy_set_header 	X-Forwarded-Server $host;
			proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header    X-Real-IP $remote_addr;
			proxy_redirect 		off;
    	}
	}

...
...
}

http://nginx.org/en/docs/http/ngx_http_proxy_module.html を参照してください。

設定ファイルへの変更は、設定をリロードするコマンドが nginx に送信されるか、nginx が再起動されるまで適用されません。設定をリロードするには、以下を実行します。

nginx -s reload

このコマンドは、nginx を開始したユーザーと同じユーザーで実行する必要があります。

Notice that we added client_max_body_size 0; to the http block of the nginx configuration because of Git push fails - client intended to send too large chunked body.


リソース

nginx の背後に Bitbucket Server をセットアップする際には、次のリソースが役立ちます。


最終更新日: 2021 年 1 月 4 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.