2

我是 Apache 菜鸟,正在尝试自动将 http://.com/gitweb 的请求重定向到 https://.com/gitweb

我已将以下内容设置为 /etc/apache2/conf.d/gitweb

Alias /gitweb /usr/share/gitweb
<Directory /usr/share/gitweb>
  Options FollowSymLinks +ExecCGI
  AddHandler cgi-script .cgi
  Redirect gitweb https://<myserver>.com/gitweb
  SSLRequireSSL
</Directory>

但是我只是不断收到 403 禁止通知

Forbidden
You don't have permission to access /gitweb on this server.
Apache/2.2.22 (Ubuntu) Server at dndo-gamma Port 80

我不希望此服务器托管的所有目录都重定向;只是对 gitweb 的请求。

我的 /etc/apache2/sites-enabled/000-default 从其默认值不变

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

文件 /etc/apache2/sites-enabled/default-ssl 也与默认的 ubuntu/apache2 安装保持不变。

4

1 回答 1

1

通常我mod_rewrite用于这些类型的任务:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteLog "/var/log/apache2/rewrite_log"

    RewriteRule ^/gitweb/(.*) https://%{SERVER_NAME}/gitweb/%1 [R]

但这不是编程,而是服务器配置;你可以考虑在serverfault.com上问这个问题

于 2013-02-11T17:30:38.050 回答