> For the complete documentation index, see [llms.txt](https://yutakatay.gitbook.io/katapedia/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yutakatay.gitbook.io/katapedia/doc/websba.md).

# Webサーバ

## リバースプロキシを立てる理由

・ワンドメイン配下に複数のサービスが出来る

・リリース切り替えが容易になる

<http://www.rickynews.com/blog/2014/08/25/why-you-need-to-use-reverse-proxy/>

## nginx

### メンテナンス画面に飛ばす

```
location / {
root   html;
index  index.html index.htm;
if (-f "/tmp/maintenance" ) {
rewrite ^(.*)$ http://172.17.0.3:8000/maintenance.html? permanent;
}
}
```

### 設定

#### proxy\_passとredirect

```
location  /foo {
rewrite /foo/(.*) /$1  break;
proxy_pass         http://localhost:3200;
proxy_redirect     off;
proxy_set_header   Host $host;
}

or

location /gitbucket {
rewrite ^/gitbucket/(.*) /$1 break;
rewrite ^/gitbucket$ /$1 break;
proxy_pass http://localhost:8082;
proxy_redirect   off;
proxy_set_header Host                   $host;
proxy_set_header X-Real-IP              $remote_addr;
proxy_set_header X-Forwarded-Proto      http;
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;
client_max_body_size 500M;
}
```

```
location  /foo {
rewrite /foo/(.*) /$1  break;
proxy_pass         http://localhost:3200;
proxy_redirect     default;
}

or

location /gitbucket {
rewrite ^/gitbucket/(.*) /$1 break;
rewrite ^/gitbucket$ /$1 break;
proxy_pass http://localhost:8082;
proxy_redirect   default;
proxy_set_header Host                   $host;
proxy_set_header X-Real-IP              $remote_addr;
proxy_set_header X-Forwarded-Proto      http;
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;
client_max_body_size 500M;
}
```

<http://anopara.matrix.jp/2015/03/13/nginxでリバースプロキシするメモ/>

前者の方がいい模様

location /foo {

rewrite ^/images/(.\*)$ <http://images.example.com/$1> redirect;

rewrite /foo/(.\*) <http://localhost:3200/$1> redirect; # permanent

}

恒久的な場合はこっち

#### proxy\_redirect

バックエンドサーバがリダイレクトした時の Location ヘッダ。 on なら proxy\_pass をホスト名としてリダイレクト。 off ならサーバの指示通りにリダイレクト。

#### rewriteのオプション

last

rewriteは完了で、以降のマッチするURI や locationの処理は継続します。

break

rewriteは完了です。

redirect

一時的なリダイレクトの意味で使います。このとき、HTTP ステータス番号 302 を返して、リダイレクトを実行します。

permanent

恒久的なリダイレクトの意味で使います。このとき、HTTP ステータス番号 301 を返して、リダイレクトを実行します

<http://server-setting.info/centos/apache-nginx-4-setting-redirect.html>

#### proxy\_set\_header

リバースプロキシを使う場合はproxy\_passは先に定義する必要がある

※Unicornなどのソケット通信の場合はproxy\_passを後ろに書いても問題ないっぽい。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://yutakatay.gitbook.io/katapedia/doc/websba.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
