0

このガイドに従って、Debian サーバーで Apache と mod_wsgi を使用して Mailman 3 をセットアップしました。

私の仮想ホストの .conf ファイル:

ErrorLog /var/log/mailman-web/mailman-web.log
CustomLog /var/log/mailman-web/mailman-web_access.log combined
WSGISocketPrefix run/wsgi
<VirtualHost *:80>
    ServerName XXXXXXX
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # Here, use the value of the STATIC_ROOT variable in your Django configuration file (production.py)
    Alias /robots.txt  /usr/local/mailman/mailman-bundler/var/mailman-web/static/hyperkitty/robots.txt
    Alias /favicon.ico /usr/local/mailman/mailman-bundler/var/mailman-web/static/hyperkitty/favicon.ico
    Alias /static      /usr/local/mailman/mailman-bundler/var/mailman-web/static

    <Directory "/usr/local/mailman/mailman-bundler/var/mailman-web/static">
        Order deny,allow
        Allow from all
        Require all granted
    </Directory>

    WSGIScriptAlias / /usr/local/mailman/mailman-bundler/bin/mailman-web.wsgi
    WSGIDaemonProcess mailman-web display-name=mailman-web maximum-requests=1000 processes=1 threads=1 python-path=/usr/local/mailman/venv/lib/python2.7/site-packages

        <Directory "/usr/local/mailman/mailman-bundler/bin">
            <Files mailman-web.wsgi>
                    Order deny,allow
                    Allow from all
                    Require all granted
            </Files>
            WSGIProcessGroup mailman-web
        </Directory>
</VirtualHost>

この設定で私が抱えている問題http://myhost/は、wsgi スクリプトに移動すると、ブラウザーがhttp://myhost/archives. ではなくにhttp://myhost/リダイレクトしたいと思います。http://myhost/mailman3http://myhost/archives

mailman がアーカイブ サブディレクトリを返すことを決定した場所を見つけようとして、apache .conf ファイルで定義されている wsgi スクリプトを調べましたが、いくつかのクラスをインポートして別のスクリプトを呼び出すだけで、それ以上のことは起きていません。このスクリプトに従って、ファイル「./eggs/Django-1.10.4-py2.7.egg/django/core/handlers/wsgi.py」、具体的には次の部分にたどり着きました。

148 class WSGIHandler(base.BaseHandler):
149     request_class = WSGIRequest
150 
151     def __init__(self, *args, **kwargs):
152         super(WSGIHandler, self).__init__(*args, **kwargs)
153         self.load_middleware()
154 
155     def __call__(self, environ, start_response):
156         set_script_prefix(get_script_name(environ))
157         signals.request_started.send(sender=self.__class__, environ=environ)
158         try:
159             request = self.request_class(environ)
160         except UnicodeDecodeError:
161             logger.warning(
162                 'Bad Request (UnicodeDecodeError)',
163                 exc_info=sys.exc_info(),
164                 extra={
165                     'status_code': 400,
166                 }
167             )
168             response = http.HttpResponseBadRequest()
169         else:
170             response = self.get_response(request)
171 
172         response._handler_class = self.__class__
173 
174         status = '%d %s' % (response.status_code, response.reason_phrase)
175         response_headers = [(str(k), str(v)) for k, v in response.items()]
176         for c in response.cookies.values():
177             response_headers.append((str('Set-Cookie'), str(c.output(header=''))))
178         start_response(force_str(status), response_headers)
179         if getattr(response, 'file_to_stream', None) is not None and environ.get('wsgi.file_wrapper'):
180             response = environ['wsgi.file_wrapper'](response.file_to_stream)
181         return response

返されるサブディレクトリの決定はここのどこかで行われると思いますが、間違っている可能性があります。

これまでに試したこと: Apache confファイルに行を追加しましたRedirect permanent / http://myhost/mailman3が、これによりApacheが次のようなURLで終わるリダイレクトループに入りましたhttp://myhost/mailman3mailman3mailman3....

誰かがこの問題で私を助けてくれることを願っています。

前もって感謝します!

4

1 に答える 1

0

サブディレクトリの決定が返ってきたのだろう

これは Django プロジェクトであるため、URL はサブディレクトリに関するものではなく、Django の「表示」機能に一致します。この場合、「決定」は次の場所で行われます。

https://gitlab.com/mailman/mailman-bundler/blob/master/mailman_web/urls.py

urlpatterns = patterns('',
    url(r'^$',RedirectView.as_view(url=reverse_lazy('hyperkitty.views.index.index'))),
    url(r'^mailman3/', include('postorius.urls')),
    url(r'^archives/', include('hyperkitty.urls')),
    url(r'', include('social.apps.django_app.urls', namespace='social'), {"SSL": True}),
    url(r'', include('django_browserid.urls'), {"SSL": True}), 
)

「ルート」URL (「r'^$'」) が hyperkitty.views.index.index にリダイレクトするように設定されていることがわかります (hyperkitty がアーカイバです)。

代わりにルート URL を「/mailman3/」にリダイレクトしたい場合は、最初のurl()行を次のように変更する必要があります。

url(r'^$',RedirectView.as_view(url="/mailman3/")),

パッケージを更新するたびに、このフォークを維持する必要があることに注意してください。

注意:同じことを行う「より良い」(より安全/クリーン/維持しやすい)方法があります(デフォルトの代わりに独自のdjango設定モジュールを使用し、所有者がこのファイルROOT_URL_CONFのコピー/貼り付け/編集バージョンを指すようにすることにより) urls.py、そして最後にreverse_lazyURL をハードコーディングする代わりに適切なものを使用することによって)、しかし、Django についてあまり知らない場合は、上記の (やや Q&D) ソリューションがはるかに簡単です。

于 2017-01-05T16:04:53.983 に答える