码迷,mamicode.com
首页 > Web开发 > 详细

突击Mercurial SCM(HG)5---Ubuntu下apache+mod_wsgi搭建hg server

时间:2015-01-22 21:56:27      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:

在《Publishing Mercurial Repositories》这篇文章中介绍了很多种将我们自己的hg代码库发布/公开的办法。其中最轻量型的办法是使用hg自带的web server发布,只需要在代码库目录下执行命令hg serve就搞定。但是这只是一个临时的方案,如果想要更健壮更安全,官网还是建议使用hgweb脚本+Web server(apache,IIS等)的方式。

查看资料后,我权衡利弊,准备以《Serving Mercurial repositories with Apache and mod_wsgi》为蓝本再结合其他教程和实践,来搭建自己的hg server供局域网中的小伙伴使用。

1.工具

mod_wsgi:apache和python沟通的桥梁。
apache2:这个家伙仍然在web server领域引领风骚。
python:2.7版本足以。
mercurial:这是我们的主角。
hgweb.wsgi:mercurial给我们提供的。

linc注:我是这WEB方面的门外汉,对cgi和wsgi等概念是一无所知,之前搭建Scrum环境是在Windows下使用傻瓜似工具,根本没机会配置apache。因此,接下来的工作令我苦不堪言。有不足之处也在所难免。更请高手指正。

2.安装

我在Ubuntu下使用apt-get install安装这些工具,十分顺利,闲言少叙。
sudo apt-get install apache2
完成后即使不做任何配置,在浏览器中输入localhost,也会出现“It works!”。那么apache就算安装成功。
sudo apt-get install libapache2-mod-wsgi
安装后在/usr/lib/apache2/modules/目录下会发现多了mod_wsgi.so
lrwxrwxrwx 1 root root     15 Nov 19 00:50 mod_wsgi.so -> mod_wsgi.so-2.7
-rw-r--r-- 1 root root 152064 Nov 19 00:50 mod_wsgi.so-2.7

3.关于apache目录这件小事

1)/var/www
这个目录是用来放置我们的网站的入口,默认这里会有个index.html,刚才我们打开localhost出现的界面就是这个index.html了。后续我们会在这个目录下做文章。
2)/etc/apache2
我们要在这里做apache的配置,重点文件有apache2.conf,httpd.conf,以及sites-available下的default。

4.配置

按照教程的例子,我也以虚拟主机 “hg.example.net"来完成整个配置。
第一步,加载mod_wsgi
我们的配置(user configurations)在/etc/apache2/httpd.conf中进行,
加载mod_wsgi只需添加LoadModule wsgi_module modules/mod_wsgi.so 即可。
linc注:后来我又将此句注释掉,发现依然运行正常。
第二步,配置apache
依例子的要求,我们要做以下工作。
1)在www下创建新文件夹
/var/www/vhosts/hg.example.net/cgi-bin
/var/www/vhosts/hg.example.net/htdocs
2)修改/etc/apache2/sites-avaiable/default
变成如下:
<VirtualHost *:80>
    ServerName hg.example.net
    DocumentRoot /var/www/vhosts/hg.example.net/htdocs

    WSGIScriptAliasMatch ^(.*)$ /var/www/vhosts/hg.example.net/cgi-bin/hgweb.wsgi$1

    <Directory /var/www/vhosts/hg.example.net/htdocs>
        Options FollowSymlinks
        DirectoryIndex index.html
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /var/www/vhosts/hg.example.net/cgi-bin>
        Options ExecCGI FollowSymlinks

        AddHandler wsgi-script .wsgi
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
第三步,配置Mercurial
1)将hgweb.wsgi文件复制到/var/www/vhosts/hg.example.net/cgi-bin/
sudo cp /usr/share/doc/mercurial-common/examples/hgweb.wsgi /var/www/vhosts/hg.example.net/cgi-bin/
修改成如下:
# Path to repo or hgweb config to serve (see ‘hg help hgweb‘)
config = "/var/www/vhosts/hg.example.net/cgi-bin/hgweb.config"

# enable demandloading to reduce startup time
from mercurial import demandimport; demandimport.enable()

from mercurial.hgweb import hgweb
application = hgweb(config)
2)hgweb.config
在/var/www/vhosts/hg.example.net/cgi-bin/新加文件hgweb.config
内如如下:
[web]
style = coal

[paths]
/ = /var/www/vhosts/hg.example.net/htdocs/**

重启apache:
sodu /etc/init.d/apache2 restart

到此,《Serving Mercurial repositories with Apache and mod_wsgi》便结束了。

第四步,创建hg代码仓库
将代码放在哪里?一直没有好主意,看到有人将其放在/var下了,姑且我也这样吧。
新建目录/var/hg/repos/test,
mkdir /var/hg/repos/test; cd /var/hg/repos/test; hg init

一个临时的代码仓库就创建完了,下面如何跟server联系在一起呢?
回过头来,我们还要修改一下hgweb.config,加入下面两句:
[collections]
/var/hg = /var/hg

重启apache后,在浏览器中输入:localhost/repos/test
你的代码库就出现了呢。这样就说明我们的工作完成了。你可能要问,直接在浏览器中输入hg.example.net不也可以吗?是这样的,但是我们还要做一项工作,在/etc/hosts文件中加入127.0.0.1   hg.example.net 才行.

好吧,先庆祝一下,下文再说代码提交遇到的问题以及身份认证问题。


参考:

http://mercurial.selenic.com/wiki/PublishingRepositories

http://mercurial.selenic.com/wiki/modwsgi

http://stackoverflow.com/questions/12347373/how-to-setup-mercurial-server-in-ubuntu-to-serve-60-repositories

http://thepanz.netsons.org/post/ubuntu-10-4-and-mercurial-server-apache2-mod_wsgi/comment-page-1

http://blog.sina.com.cn/s/blog_4567bb800100whho.html

http://blog.csdn.net/tony1130/article/details/5326015

http://blog.csdn.net/kongdaoxian/article/details/7944872

突击Mercurial SCM(HG)5---Ubuntu下apache+mod_wsgi搭建hg server

标签:

原文地址:http://blog.csdn.net/lincyang/article/details/42779523

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!