在我的 ubuntu 18.04 vps 上使用 apache 2.4 调试 cgit 的设置

在我的 ubuntu 18.04 vps 上使用 apache 2.4 调试 cgit 的设置

背景

我想在我的 ubuntu 18.04 vps 上使用 apache 2.4 设置 cgit。我已经有 git 服务器运行,并可以自己使用 ssh 访问。但我还想为我的存储库安装一个 Web 查看器。

调试过程

当我访问我的子域名 (git.example.com) 时,出现未找到错误。apache 错误日志未显示任何错误。apache 访问日志显示 404 状态。这让我认为 apache 无法查看这些文件。但是,这些文件存在,并且似乎允许 apache 的 www-data 用户读取和写入(根据需要执行)。

问题

我不确定如何继续调试这个问题。

权限

user@vps ~$ sudo -u www-data ls -l /home/www-data/cgit
total 1148
-rwxrwsr-x 1 www-data gitusers 1140464 Jul 26 03:08 cgit.cgi
-rw-rwSr-- 1 www-data gitusers   14237 Jul 26 03:08 cgit.css
-rw-rwSr-- 1 www-data gitusers    1278 Jul 26 03:08 cgit.png
-rw-rwSr-- 1 www-data gitusers    1078 Jul 26 03:08 favicon.ico
drwxrwsr-x 3 www-data gitusers    4096 Jul 26 03:08 filters
-rw-rwSr-- 1 www-data gitusers      47 Jul 26 03:08 robots.txt

错误日志

No error

访问日志

[ip address] - - [utc timestamp] "GET / HTTP/1.1" 404 3950 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0"

浏览器显示

Not Found

The requested URL / was not found on this server.
Apache/2.4.29 (Ubuntu) Server at git.example.com Port 443

VirtualHost 文件

<VirtualHost *:443>
    #======================================================================#
    # Basic admin setings                                                  #
    #======================================================================#

    ServerAdmin [email protected]
    ServerName git.example.com
    ServerAlias www.git.example.com
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ErrorLog ${APACHE_LOG_DIR}/error.log

    #======================================================================#
    # cgit settings                                                        #
    #======================================================================#

    DocumentRoot /home/www-data/cgit
    SetEnv CGIT_CONFIG  /home/www-data/cgit/cgitrc
    Alias /cgit.css     /home/www-data/cgit/cgit.css
    Alias /cgit.png     /home/www-data/cgit/cgit.png
    Alias /favicon.ico  /home/www-data/cgit/favicon.ico
    Alias /robots.txt   /home/www-data/cgit/robots.txt
    Alias /             /home/www-data/cgit/cgit.cgi/

    <Directory /home/www-data/cgit>
      Options Indexes FollowSymLinks ExecCGI
      AllowOverride None
      Require all granted
      AddHandler cgi-script .cgi
      DirectoryIndex cgit.cgi
    </Directory>

    RewriteEngine on
    RewriteRule ^/(.*\.git(|(/(?!(HEAD|info|objects|refs|git-(upload|receive)-pack)).*)))?$ /home/www-data/cgit/cgit.cgi/$1
    Alias /cgit-css /home/www-data/cgit/

    #======================================================================#
    # Use Git's Smart HTTP Protocol                                        #
    #======================================================================#

    # Allow exporting of all repos. To choose which repos to allow exporting of,
    # comment this out and use touch /path/to/repo.git/git-daemon-export-ok
    # for each exportable repo.
    SetEnv GIT_HTTP_EXPORT_ALL

    # Set location of git repos.
    SetEnv GIT_PROJECT_ROOT /home/git

    # Make writes require authentication via apache gitusers password file.
    <Files "git-http-backend">
        AuthType Basic
        AuthName "git.example.com Git Repo Push Access"
        AuthUserFile /home/git/gitusers
        Require valid-user
    </Files>
    #Alternatives to the require expr above
    ScriptAliasMatch "^/(.*\.git/(HEAD|info/refs))$" /usr/lib/git-core/git-http-backend/$1
    ScriptAliasMatch "^/(.*\.git/git-(upload|receive)-pack)$" /usr/lib/git-core/git-http-backend/$1

    #======================================================================#
    # SSL configuration                                                    #
    #======================================================================#

    SSLEngine on
    SSLProtocol -ALL -SSLv2 -SSLv3 +TLSv1 +TLSv1.1 +TLSv1.2
    SSLHonorCipherOrder on
    SSLCipherSuite TLSv1.2:RC4:HIGH:!aNULL:!eNULL:!MD5
    SSLCompression off
    TraceEnable Off
    SSLCertificateFile "/etc/letsencrypt/live/example.com/fullchain.pem"
    SSLCertificateKeyFile "/etc/letsencrypt/live/example.com/privkey.pem"
</VirtualHost>

答案1

终于让它工作了。看起来主要问题是DirectoryIndex指令的存在。否则,我只是移动了一些指令。以下是更正后的 cgit 部分。

#======================================================================#
# cgit settings                                                        #
#======================================================================#

# Set the root location of cgit files.
# With the aliases used as below, cgit expects the left alias path in its
# cgitrc file.
DocumentRoot /home/www-data/cgit/

# Set the location of the cgit config file.
SetEnv CGIT_CONFIG  /home/www-data/cgit/cgitrc

# Set aliases for cleaner urls.
Alias /cgit.css     /home/www-data/cgit/cgit.css
Alias /cgit.png     /home/www-data/cgit/cgit.png
Alias /favicon.ico  /home/www-data/cgit/favicon.ico
Alias /robots.txt   /home/www-data/cgit/robots.txt
Alias /cgit-css     /home/www-data/cgit
ScriptAlias /       /home/www-data/cgit/cgit.cgi/

# Set directory options for the directory holding cgit files.
<Directory /home/www-data/cgit>
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride None
    Require all granted
    AddHandler cgi-script .cgi
</Directory>

RewriteEngine on
RewriteRule ^/(.*\.git(|(/(?!(HEAD|info|objects|refs|git-upload-pack)).*)))?$ /home/www-data/cgit/cgit.cgi/$1

请注意,我还删除了接收包选项,因为我只想允许通过 ssh 推送,但通过 https 和 ssh 克隆是可以的。

相关内容