尝试在内部自托管阅读文档,但对 Django 的经验很少。
我已经按照readthedocs上的所有步骤(在我拥有的 /usr/share/ 中创建 virtualenv 并拥有组所有权 www-data)用于开发网络服务器,并且效果很好。
已采取以下附加步骤将 wsgi 和 apache 设置为 selfhost:
安装了额外的依赖
- sudo apt-get install libapache2-mod-wsgi libpq-dev redis-server
- cd /usr/share/readthedocs/
- pip install psycopg2 redis django-redis-cache django-redis-sessions
- pip install --upgradehiredis
配置redis监听socket并放宽权限到777
apache被配置为一个虚拟主机:
<VirtualHost *:80>
ServerName docs.vagrant
WSGIScriptAlias / /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/wsgi.py
WSGIProcessGroup www-data
WSGIDaemonProcess www-data \
python-path=/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/:/usr/share/readthedocs/lib/python2.7/site-packages/:/usr/share/readthedocs/:/usr/share/readthedocs/checkouts/readthedocs.org/:/usr/share/readthedocs/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/
<Directory /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
并且流量似乎正确地流向了后端。然而,RTD 抱怨缺少 REDIS 属性。Apache 错误日志输出:
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Starting process 'www-data' with uid=33, gid=33 and threads=15.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Initializing Python.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Attach interpreter ''.
[wsgi:info] [pid 19596] mod_wsgi (pid=19596): Attach interpreter ''.
[wsgi:info] [pid 19597] mod_wsgi (pid=19597): Attach interpreter ''.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/lib/python2.7/site-packages/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/checkouts/readthedocs.org/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Create interpreter 'docs.vagrant:3380|'.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/lib/python2.7/site-packages/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/checkouts/readthedocs.org/' to path.
[wsgi:info] [pid 19595] mod_wsgi (pid=19595): Adding '/usr/share/readthedocs/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/' to path.
[wsgi:info] [pid 19595] [remote 10.0.2.2:512] mod_wsgi (pid=19595, process='www-data', application='docs.vagrant:3380|'): Loading WSGI script '/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/wsgi.py'.
[wsgi:info] [pid 19624] mod_wsgi (pid=19624): Initializing Python.
[wsgi:info] [pid 19624] mod_wsgi (pid=19624): Attach interpreter ''.
[wsgi:error] [pid 19595] [09/Sep/2015 10:30:01] WARNING [readthedocs.api.client:16] SLUMBER_USERNAME/PASSWORD settings are not set
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] mod_wsgi (pid=19595): Exception occurred processing WSGI script '/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/wsgi.py'.
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] Traceback (most recent call last):
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] self.load_middleware()
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/handlers/base.py", line 52, in load_middleware
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] mw_instance = mw_class()
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/middleware/locale.py", line 24, in __init__
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] for url_pattern in get_resolver(None).url_patterns:
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/urlresolvers.py", line 402, in url_patterns
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/urlresolvers.py", line 396, in urlconf_module
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] self._urlconf_module = import_module(self.urlconf_name)
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] __import__(name)
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/urls.py", line 8, in <module>
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] from readthedocs.api.base import (ProjectResource, UserResource,
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/api/base.py", line 28, in <module>
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] redis_client = redis.Redis(**settings.REDIS)
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in __getattr__
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] return getattr(self._wrapped, name)
[wsgi:error] [pid 19595] [remote 10.0.2.2:512] AttributeError: 'Settings' object has no attribute 'REDIS'
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] mod_wsgi (pid=19595): Exception occurred processing WSGI script '/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/wsgi.py'.
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] Traceback (most recent call last):
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] self.load_middleware()
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/handlers/base.py", line 52, in load_middleware
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] mw_instance = mw_class()
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/middleware/locale.py", line 24, in __init__
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] for url_pattern in get_resolver(None).url_patterns:
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/urlresolvers.py", line 402, in url_patterns
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/core/urlresolvers.py", line 396, in urlconf_module
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] self._urlconf_module = import_module(self.urlconf_name)
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] __import__(name)
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/urls.py", line 8, in <module>
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] from readthedocs.api.base import (ProjectResource, UserResource,
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/api/base.py", line 28, in <module>
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] redis_client = redis.Redis(**settings.REDIS)
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] File "/usr/share/readthedocs/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in __getattr__
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] return getattr(self._wrapped, name)
[wsgi:error] [pid 19595] [remote 10.0.2.2:51327] AttributeError: 'Settings' object has no attribute 'REDIS'
我意识到我还需要启用弹性搜索并进行正确配置,但是当我走到那一步时,我会越过那座桥。
更新:发出grep -i redis /usr/share/readthedocs/checkouts/readthedocs.org/readthedocs/settings/*
返回的命令
__init__.py: 'BACKEND': 'redis_cache.RedisCache',
__init__.py: 'PARSER_CLASS': 'redis.connection.HiredisParser'
onebox.py:REDIS = {
onebox.py:BROKER_URL = 'redis://localhost:6379/0'
onebox.py:CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
onebox.py: 'BACKEND': 'redis_cache.cache.RedisCache',
onebox.py: 'CLIENT_CLASS': 'redis_cache.client.DefaultClient',
postgres.py: 'BACKEND': 'redis_cache.RedisCache',
postgres.py: 'PARSER_CLASS': 'redis.connection.HiredisParser'
sqlite.py:REDIS = {
sqlite.py:BROKER_URL = 'redis://localhost:6379/0'
sqlite.py:CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
所以我重新配置redis不再使用套接字并返回绑定/端口,但问题仍然存在(使用相同的堆栈跟踪)。