Skip to content

Translate 04-git-server smart-http #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions book/04-git-server/sections/smart-http.asc
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
=== Smart HTTP

(((serving repositories, HTTP)))
We now have authenticated access though SSH and unauthenticated access through `git://`, but there is also a protocol that can do both at the same time.
Setting up Smart HTTP is basically just enabling a CGI script that is provided with Git called `git-http-backend` on the server.((git commands, "http-backend"))
This CGI will read the path and headers sent by a `git fetch` or `git push` to an HTTP URL and determine if the client can communicate over HTTP (which is true for any client since version 1.6.6).
If the CGI sees that the client is smart, it will communicate smartly with it, otherwise it will fall back to the dumb behavior (so it is backward compatible for reads with older clients).
我们一般通过 SSH 进行授权访问,通过 git:// 进行无授权访问,但是还有一种协议可以同时实现以上两种方式的访问。
设置 Smart HTTP 一般只需要在服务器上启用一个 Git 自带的名为 `git-http-backend` 的 CGI 脚本。((git commands, "http-backend"))
CGI 脚本将会读取由 `git fetch` `git push` 命令向 HTTP URL 发送的请求路径和头部信息,来判断该客户端是否支持 HTTP 通信(不低于 1.6.6 版本的客户端支持此特性)。
如果 CGI 发现该客户端支持智能(Smart)模式,它将会以智能模式与它进行通信,否则它将会回落到哑(Dumb)模式下(因此它可以对某些老的客户端实现向下兼容)。

Let's walk though a very basic setup. We'll set this up with Apache as the CGI server. If you don't have Apache setup, you can do so on a Linux box with something like this:(((Apache)))
在完成以上简单的安装步骤后,我们将用 Apache 来作为 CGI 服务器。如果你没有安装 Apache,你可以在 Linux 环境下执行如下或类似的命令来安装:(((Apache)))

[source,console]
----
$ sudo apt-get install apache2 apache2-utils
$ a2enmod cgi alias env
----

This also enables the `mod_cgi`, `mod_alias`, and `mod_env` modules, which are all needed for this to work properly.
该操作将会启用 `mod_cgi` `mod_alias`, 和 `mod_env` 等 Apache 模块, 这些模块都是使该功能正常工作所必须的。

Next we need to add some things to the Apache configuration to run the `git http-backend` as the handler for anything coming into the `/git` path of your web server.
接下来我们要向 Apache 配置文件添加一些内容,来让 `git http-backend` 作为 Web 服务器对 `/git` 路径请求的处理器。

[source,console]
----
Expand All @@ -25,9 +25,9 @@ SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
----

If you leave out `GIT_HTTP_EXPORT_ALL` environment variable, then Git will only serve to unauthenticated clients the repositories with the `git-daemon-export-ok` file in them, just like the Git daemon did.
如果留空 `GIT_HTTP_EXPORT_ALL` 这个环境变量,Git 将只对无授权客户端提供带 `git-daemon-export-ok` 文件的版本库,就像 Git 守护进程一样。

Then you'll have to tell Apache to allow requests to that path with something like this:
接着你需要让 Apache 接受通过该路径的请求,添加如下的内容至 Apache 配置文件:

[source,console]
----
Expand All @@ -39,7 +39,7 @@ Then you'll have to tell Apache to allow requests to that path with something li
</Directory>
----

Finally you'll want to make writes be authenticated somehow, possibly with an Auth block like this:
最后,如果想实现写操作授权验证,使用如下的未授权屏蔽配置即可:

[source,console]
----
Expand All @@ -51,18 +51,18 @@ Finally you'll want to make writes be authenticated somehow, possibly with an Au
</LocationMatch>
----

That will require you to create a `.htaccess` file containing the passwords of all the valid users. Here is an example of adding a ``schacon'' user to the file:
这需要你创建一个包含所有合法用户密码的 `.htaccess` 文件。以下是一个添加 ``schacon'' 用户到此文件的例子:

[source,console]
----
$ htdigest -c /opt/git/.htpasswd "Git Access" schacon
----

There are tons of ways to have Apache authenticate users, you'll have to choose and implement one of them. This is just the simplest example we could come up with. You'll also almost certainly want to set this up over SSL so all this data is encrypted.
你可以通过许多方式添加 Apache 授权用户,选择使用其中一种方式即可。以上仅仅只是我们可以找到的最简单的一个例子。如果愿意的话,你也可以通过 SSL 运行它,以保证所有数据是在加密状态下进行传输的。

We don't want to go too far down the rabbit hole of Apache configuration specifics, since you could well be using a different server or have different authenication needs. The idea is that Git comes with a CGI called `git http-backend` that when invoked will do all the negotiation to send and receive data over HTTP. It does not implement any authentication itself, but that can easily be controlled at the layer of the web server that invokes it. You can do this with nearly any CGI-capable web server, so go with the one that you know best.
我们不想深入去讲解 Apache 配置文件,因为你可能会使用不同的 Web 服务器,或者可能有不同的授权需求。它的主要原理是使用一个 Git 附带的,名为 `git http-backend` 的 CGI。它被引用来处理协商通过 HTTP 发送和接收的数据。它本身并不包含任何授权功能,但是授权功能可以在 Web 服务器层引用它时被轻松实现。你可以在任何所有可以处理 CGI 的 Web 服务器上办到这点,所以随便挑一个你最熟悉的 Web 服务器试手吧。

[NOTE]
====
For more information on configuring authentication in Apache, check out the Apache docs here: http://httpd.apache.org/docs/current/howto/auth.html[]
欲了解更多的有关配置 Apache 授权访问的信息,请通过以下链接浏览 Apache 文档: http://httpd.apache.org/docs/current/howto/auth.html[]
====
2 changes: 1 addition & 1 deletion status.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"sections/hosted.asc": 0,
"sections/protocols.asc": 17,
"sections/setting-up-server.asc": 0,
"sections/smart-http.asc": 0
"sections/smart-http.asc": 100
},
"05-distributed-git": {
"1-distributed-git.asc": 0,
Expand Down