将 Django 与 Apache、mod-wsgi 和 mod-wsgi_httpd 结合使用
using Django with Apache, mod-wsgi and mod-wsgi_httpd
(对不起,我的英语可能不流利。)
我正在研究 Django,一个 mod 的 Python 规则,Windows10,有什么想问的。
我学习了Django官网的教程。现在我想尝试将它与 apache 和 mod-wsgi 一起使用,但是命令 pip install mod-wsgi_httpd
没有被接受。
这是我已经完成或检查过的内容。
1. python3.6 没有问题。
2. 安装apache,并成功在localhost 的80 端口显示默认页面。
3. 命令 pip install mod_wsgi
没有被接受,所以我安装了 'whl' 文件
https://www.ifd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
但我没有检查它是否工作正常,因为我没有安装 mod-wsgi_httpd。 pip install mod_wsgi
产生了这个错误,我无法处理。(我提取了后面的部分,因为日志太长了。)
copying docs\_build\html\security-issues.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying docs\_build\html\source-code.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying docs\_build\html\troubleshooting.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying docs\_build\html\user-guides.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying images\snake-whiskey.jpg -> build\lib.win-amd64-3.6\mod_wsgi\images
running build_ext
building 'mod_wsgi.server.mod_wsgi' extension
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\python\python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "c:\python\python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "c:\python\python36\lib\distutils\_msvccompiler.py", line 69, in _getall
all_packages.extend(_distutils_findvs.findall())
OSError: Error 80070002
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\src
creating build\temp.win-amd64-3.6\Release\src\server
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-IC:/Program Files/Apache/Apache24/include" -Ic:\python\python36\include -Ic:\python\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\shared" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\winrt" /Tcsrc/server\mod_wsgi.c /Fobuild\temp.win-amd64-3.6\Release\src/server\mod_wsgi.obj
mod_wsgi.c
c:\python\python36\include\pyconfig.h(307): warning C4005: 'PLATFORM': macro redefinition
c:\program files\apache\apache24\include\os.h(42): note: see previous definition of 'PLATFORM'
src/server\mod_wsgi.c(471): warning C4267: 'initializing': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(472): warning C4267: 'initializing': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(580): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(729): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(775): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(1860): warning C4244: '=': conversion from 'Py_ssize_t' to 'long', possible loss of data
src/server\mod_wsgi.c(3434): warning C4244: '=': conversion from 'Py_ssize_t' to 'long', possible loss of data
src/server\mod_wsgi.c(4251): error C2065: 'wsgi_daemon_process': undeclared identifier
src/server\mod_wsgi.c(4417): error C2065: 'wsgi_daemon_process': undeclared identifier
src/server\mod_wsgi.c(4417): error C2223: left of '->group' must point to struct/union
src/server\mod_wsgi.c(6052): warning C4244: 'return': conversion from '__int64' to 'long', possible loss of data
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
----------------------------------------
Command "c:\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\拓海\AppData\Local\Temp\pip-build-brq4sh13\mod-wsgi\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\拓海\AppData\Local\Temp\pip-zwr3dv_t-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\拓海\AppData\Local\Temp\pip-build-brq4sh13\mod-wsgi\
我会在这个问题的最后回复命令提示符。
我想问的就是这些
1.安装mod-wsgi_httpd怎么办?
2. mod-wsgi_httpd 有什么用? (Django官网说了mod-wsgi,没说mod-wsgi_httpd。Python官网也说了,不过对我来说太抽象了。)
3. 有些网站告诉我apache 没有APR 就不能工作,但apache 使我没有安装APR 的默认页面。这个信息有误吗?
C:\Users\拓海>pip install mod-wsgi_httpd
Collecting mod-wsgi_httpd
Using cached mod_wsgi-httpd-2.4.27.1.tar.gz
Complete output from command python setup.py egg_info:
'rm' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\拓海\AppData\Local\Temp\pip-build-zt76ing5\mod-wsgi-httpd\setup.py", line 77, in <module>
raise RuntimeError('Failed to build APR.')
RuntimeError: Failed to build APR.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\拓海\AppData\Local\Temp\pip-build-zt76ing5\mod-wsgi-httpd\
C:\Users\拓海>python --version
Python 3.6.4
C:\Users\拓海>pip freeze
Django==2.0.2
mod-wsgi==4.5.24+ap24vc14
mysql-connector-python==8.0.6
PyMySQL==0.8.0
pytz==2018.3
C:\Program Files\Apache\Apache24>bin\httpd.exe -v
Server version: Apache/2.4.29 (Win64)
Apache Lounge VC15 Server built: Nov 3 2017 11:12:00
确保启用 WSGI 是这里的第一步。
首先确保您在 Apache 中加载 WSGI 模块。找出其他 LoadModule 行所在的位置并将其加载到那里。它应该在 conf\httpd.conf
中的 Apache 目录中。重新启动 Apache 并确保 WSGI 模块由 运行 httpd -t -D DUMP_MODULES
或 apachectl -M
.
加载
在连接 Django 之前,最好确保加载测试脚本。查看 the WSGI Quick Configuration Guide。您会看到一些片段。
- 第一个片段是一个 WSGI 脚本,你应该把它放在 Apache 可以访问的地方(但不在 Django 目录中)。
- 第二个和第三个脚本位于 apache2 配置文件中的 VirtualHost 指令中。有关使用 WSGI 的 VirtualHost 示例,请参阅第四个脚本。 (您可能想在不同的端口 [不是 80 或 8000] 上为此 WSGI 测试脚本设置另一个 VirtualHost。)
创建脚本并配置 apache2 VirtualHost 后,您应该会看到 WSGI 脚本显示 'Hello World!'。如果没有,则说明某些内容未正确安装。检查 Apache 的错误日志。
(对不起,我的英语可能不流利。)
我正在研究 Django,一个 mod 的 Python 规则,Windows10,有什么想问的。
我学习了Django官网的教程。现在我想尝试将它与 apache 和 mod-wsgi 一起使用,但是命令 pip install mod-wsgi_httpd
没有被接受。
这是我已经完成或检查过的内容。
1. python3.6 没有问题。
2. 安装apache,并成功在localhost 的80 端口显示默认页面。
3. 命令 pip install mod_wsgi
没有被接受,所以我安装了 'whl' 文件
https://www.ifd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
但我没有检查它是否工作正常,因为我没有安装 mod-wsgi_httpd。 pip install mod_wsgi
产生了这个错误,我无法处理。(我提取了后面的部分,因为日志太长了。)
copying docs\_build\html\security-issues.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying docs\_build\html\source-code.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying docs\_build\html\troubleshooting.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying docs\_build\html\user-guides.html -> build\lib.win-amd64-3.6\mod_wsgi\docs
copying images\snake-whiskey.jpg -> build\lib.win-amd64-3.6\mod_wsgi\images
running build_ext
building 'mod_wsgi.server.mod_wsgi' extension
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\python\python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "c:\python\python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "c:\python\python36\lib\distutils\_msvccompiler.py", line 69, in _getall
all_packages.extend(_distutils_findvs.findall())
OSError: Error 80070002
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\src
creating build\temp.win-amd64-3.6\Release\src\server
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-IC:/Program Files/Apache/Apache24/include" -Ic:\python\python36\include -Ic:\python\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\shared" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.16299.0\winrt" /Tcsrc/server\mod_wsgi.c /Fobuild\temp.win-amd64-3.6\Release\src/server\mod_wsgi.obj
mod_wsgi.c
c:\python\python36\include\pyconfig.h(307): warning C4005: 'PLATFORM': macro redefinition
c:\program files\apache\apache24\include\os.h(42): note: see previous definition of 'PLATFORM'
src/server\mod_wsgi.c(471): warning C4267: 'initializing': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(472): warning C4267: 'initializing': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(580): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(729): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(775): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data
src/server\mod_wsgi.c(1860): warning C4244: '=': conversion from 'Py_ssize_t' to 'long', possible loss of data
src/server\mod_wsgi.c(3434): warning C4244: '=': conversion from 'Py_ssize_t' to 'long', possible loss of data
src/server\mod_wsgi.c(4251): error C2065: 'wsgi_daemon_process': undeclared identifier
src/server\mod_wsgi.c(4417): error C2065: 'wsgi_daemon_process': undeclared identifier
src/server\mod_wsgi.c(4417): error C2223: left of '->group' must point to struct/union
src/server\mod_wsgi.c(6052): warning C4244: 'return': conversion from '__int64' to 'long', possible loss of data
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
----------------------------------------
Command "c:\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\拓海\AppData\Local\Temp\pip-build-brq4sh13\mod-wsgi\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\拓海\AppData\Local\Temp\pip-zwr3dv_t-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\拓海\AppData\Local\Temp\pip-build-brq4sh13\mod-wsgi\
我会在这个问题的最后回复命令提示符。
我想问的就是这些
1.安装mod-wsgi_httpd怎么办?
2. mod-wsgi_httpd 有什么用? (Django官网说了mod-wsgi,没说mod-wsgi_httpd。Python官网也说了,不过对我来说太抽象了。)
3. 有些网站告诉我apache 没有APR 就不能工作,但apache 使我没有安装APR 的默认页面。这个信息有误吗?
C:\Users\拓海>pip install mod-wsgi_httpd
Collecting mod-wsgi_httpd
Using cached mod_wsgi-httpd-2.4.27.1.tar.gz
Complete output from command python setup.py egg_info:
'rm' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\拓海\AppData\Local\Temp\pip-build-zt76ing5\mod-wsgi-httpd\setup.py", line 77, in <module>
raise RuntimeError('Failed to build APR.')
RuntimeError: Failed to build APR.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\拓海\AppData\Local\Temp\pip-build-zt76ing5\mod-wsgi-httpd\
C:\Users\拓海>python --version
Python 3.6.4
C:\Users\拓海>pip freeze
Django==2.0.2
mod-wsgi==4.5.24+ap24vc14
mysql-connector-python==8.0.6
PyMySQL==0.8.0
pytz==2018.3
C:\Program Files\Apache\Apache24>bin\httpd.exe -v
Server version: Apache/2.4.29 (Win64)
Apache Lounge VC15 Server built: Nov 3 2017 11:12:00
确保启用 WSGI 是这里的第一步。
首先确保您在 Apache 中加载 WSGI 模块。找出其他 LoadModule 行所在的位置并将其加载到那里。它应该在 conf\httpd.conf
中的 Apache 目录中。重新启动 Apache 并确保 WSGI 模块由 运行 httpd -t -D DUMP_MODULES
或 apachectl -M
.
在连接 Django 之前,最好确保加载测试脚本。查看 the WSGI Quick Configuration Guide。您会看到一些片段。
- 第一个片段是一个 WSGI 脚本,你应该把它放在 Apache 可以访问的地方(但不在 Django 目录中)。
- 第二个和第三个脚本位于 apache2 配置文件中的 VirtualHost 指令中。有关使用 WSGI 的 VirtualHost 示例,请参阅第四个脚本。 (您可能想在不同的端口 [不是 80 或 8000] 上为此 WSGI 测试脚本设置另一个 VirtualHost。)
创建脚本并配置 apache2 VirtualHost 后,您应该会看到 WSGI 脚本显示 'Hello World!'。如果没有,则说明某些内容未正确安装。检查 Apache 的错误日志。