在window服务器上配置django项目,使用apache+mod_wigs,
配置文件如下:
# 监听9080端口
Listen 8000
# 加载mod_wsgi模块
LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python37"
# 配置Django项目的应用程序路径
WSGIPythonPath "C:/website/website"
<VirtualHost *:8000>
ServerName localhost
DocumentRoot "C:/website"
Alias /static/ "C:/website/static/"
<Directory "C:/website/static">
Require all granted
</Directory>
WSGIScriptAlias / "C:/website/website/wsgi.py"
<Directory "C:/website/website">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
报错信息
[Sun Jun 04 11:16:06.786712 2023] [core:notice] [pid 4920:tid 312] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24 -f C:\\Apache24\\conf\\httpd.conf'
[Sun Jun 04 11:16:06.802456 2023] [mpm_winnt:notice] [pid 4920:tid 312] AH00418: Parent: Created child process 6724
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'Current thread 0x00001a6c (most recent call first):
[Sun Jun 04 11:16:28.927629 2023] [mpm_winnt:crit] [pid 4920:tid 312] AH00419: master_main: create child process failed. Exiting.
说明:apache 启动了但是因为没有找到python的某个包“encodings” ,导致退出创建的进程。
解决办法:确认配置文件中所有的路径都是存在的,可以通过cmd命令提示符窗口运行python的命令,导入,输出模块的相关信息,然后添加环境变量PYTHONHOME
PYTHONHOME
c:/users/administrator/appdata/local/programs/python/python37
变量名为 PYTHONHOME,变量值为python的安装路径。