Mercurial > self-hosted
comparison Mercurial/doc/Install-Mercurial-on-Ubuntu.md @ 0:edd512324c03
Add:Mercurial Files
| author | Pluto <meokcin@gmail.com> |
|---|---|
| date | Tue, 03 Sep 2024 16:30:52 +0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:edd512324c03 |
|---|---|
| 1 # Ubuntu下 apache2 和 hgweb 的安装 | |
| 2 ## 安装 | |
| 3 1. 安装 apache2、 hgweb | |
| 4 ```shell | |
| 5 sudo apt install apache2 mercurial libapache2-mod-wsgi-py3 apache2-utils | |
| 6 ``` | |
| 7 2. 验证环境 | |
| 8 ```shell | |
| 9 # 启用apache2 | |
| 10 sudo systemctl start apache2 | |
| 11 sudo systemctl enable apache2 | |
| 12 | |
| 13 # 查看HG | |
| 14 hg --version | |
| 15 ``` | |
| 16 3. 创建文件夹和默认仓库 | |
| 17 ```shell | |
| 18 sudo mkdir /var/hg | |
| 19 sudo hg init /var/hg/myrepo | |
| 20 | |
| 21 #设置文件夹权限 | |
| 22 sudo chown -R www-data:www-data /var/hg | |
| 23 sudo chmod -R 755 /var/hg | |
| 24 ``` | |
| 25 4. 创建 ```/var/hg/hgweb.config``` 文件 | |
| 26 ```shell | |
| 27 [web] | |
| 28 allow_push = * | |
| 29 push_ssl = true | |
| 30 allow_archive = gz, zip, bz2 | |
| 31 | |
| 32 [paths] | |
| 33 / = /var/hg/* | |
| 34 ``` | |
| 35 | |
| 36 5. 创建 ``` /var/hg/hgweb.wsgi``` 文件 | |
| 37 ```shell | |
| 38 import sys | |
| 39 import os | |
| 40 from mercurial import demandimport | |
| 41 demandimport.enable() | |
| 42 | |
| 43 # 设置编码为UTF-8 | |
| 44 if not isinstance(os.environ.get('PYTHONIOENCODING'), str): | |
| 45 os.environ['PYTHONIOENCODING'] = 'utf-8' | |
| 46 | |
| 47 from mercurial.hgweb.hgwebdir_mod import hgwebdir | |
| 48 | |
| 49 application = hgwebdir(b'/var/hg/hgweb.config') | |
| 50 ``` | |
| 51 6. 创建 ```/etc/apache2/sites-available/hgweb.conf``` | |
| 52 ```shell | |
| 53 <VirtualHost *:80> | |
| 54 ServerName repo.nnsui.com | |
| 55 | |
| 56 RewriteEngine On | |
| 57 RewriteCond %{HTTPS} !=on | |
| 58 RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] | |
| 59 </VirtualHost> | |
| 60 | |
| 61 <VirtualHost *:443> | |
| 62 ServerName repo.nnsui.com | |
| 63 | |
| 64 SSLEngine On | |
| 65 SSLCertificateFile /etc/apache2/cert/nnsui.com.pem | |
| 66 SSLCertificateKeyFile /etc/apache2/cert/nnsui.com.key | |
| 67 | |
| 68 WSGIScriptAlias / /var/hg/hgweb.wsgi | |
| 69 WSGIDaemonProcess hgweb user=www-data group=www-data processes=2 threads=15 | |
| 70 WSGIProcessGroup hgweb | |
| 71 | |
| 72 <Directory /var/hg> | |
| 73 Require all granted | |
| 74 </Directory> | |
| 75 | |
| 76 <Location "/"> | |
| 77 AuthType Basic | |
| 78 AuthName "Restricted Access" | |
| 79 AuthUserFile /etc/apache2/hgweb.htpasswd | |
| 80 Require valid-user | |
| 81 <Limit GET> | |
| 82 Require all granted | |
| 83 </Limit> | |
| 84 <LimitExcept GET> | |
| 85 Require valid-user | |
| 86 </LimitExcept> | |
| 87 </Location> | |
| 88 </VirtualHost> | |
| 89 ``` | |
| 90 | |
| 91 7. 启用apache2模块 | |
| 92 ```shell | |
| 93 sudo a2enmod wsgi | |
| 94 sudo a2enmod ssl | |
| 95 sudo a2enmod rewrite | |
| 96 ``` | |
| 97 8. 启动! | |
| 98 ```shell | |
| 99 # 检查配置 | |
| 100 sudo apachectl configtest | |
| 101 # 重启 | |
| 102 sudo a2ensite hgweb | |
| 103 | |
| 104 sudo systemctl restart apache2 | |
| 105 ``` | |
| 106 9. 创建 ```htpasswd``` 文件并添加用户 | |
| 107 ```shell | |
| 108 sudo htpasswd -c /etc/apache2/hgweb.htpasswd pluto | |
| 109 ``` | |
| 110 | |
| 111 10. |
