apache配置python mod_wsgi的方法
发表于:2026-11-05 作者:千家信息网编辑
千家信息网最后更新 2026年11月05日,本篇内容主要讲解"apache配置python mod_wsgi的方法",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"apache配置python mod_
千家信息网最后更新 2026年11月05日apache配置python mod_wsgi的方法
本篇内容主要讲解"apache配置python mod_wsgi的方法",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"apache配置python mod_wsgi的方法"吧!
apt-get升级
# 更新源apt-get update
python环境安装
# 安装python3apt-get install python3python -Vls /usr/bin/python*cd /usr/bin/ln -s python3 pythonpython -V# 基础安装apt-get install curl wget vim# 时区设置 or tzselectapt-get install tzdatadate -R# 安装pipcd tmp/curl https://bootstrap.pypa.io/get-pip.py -o get-pip.pypython get-pip.py此处会报错Traceback (most recent call last): File "get-pip.py", line 22308, inmain() File "get-pip.py", line 197, in main bootstrap(tmpdir=tmpdir) File "get-pip.py", line 82, in bootstrap import pip._internal File "/tmp/tmpslqx710t/pip.zip/pip/_internal/__init__.py", line 40, in File "/tmp/tmpslqx710t/pip.zip/pip/_internal/cli/autocompletion.py", line 8, in File "/tmp/tmpslqx710t/pip.zip/pip/_internal/cli/main_parser.py", line 7, in File "/tmp/tmpslqx710t/pip.zip/pip/_internal/cli/cmdoptions.py", line 15, in ModuleNotFoundError: No module named 'distutils.util'需要安装apt-get install python3-distutilspython get-pip.pypip list
django安装
# django安装pip install djangopip install requestspip install openpyxlpip install six# 安装mysqlclient前需要安装,否则会报下面所列错误apt-get install libmysqlclient-dev python3-dev build-essentialpip install mysqlclient错误1. OSError: mysql_config not found2. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
apache2环境安装
# 安装 apachesudo apt-get install apache2# 启动 apachesudo service apache2 start# 安装 mod_wsgisudo apt-get install libapache2-mod-wsgi-py3# 验证 mod_wsgi 安装sudo find / -name mod_wsgi.so# 原理实际安装完libapache2-mod-wsgi-py3会生成一个mod_wsgi.so的文件,位于/usr/lib/apache2/modules/mod_wsgi.so而apache2和它的关联在下面root@fe71dd7317b0:/etc/apache2# cat mods-available/wsgi.loadLoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so这个地方要注意python3的版本,ubuntu16.04默认源是python3.5的,其用上面命令安装的mod_wsgi都是3.5的,需要更改有的通过pip安装mod_wsgi,再修改mods-available/wsgi.load里mod_wsgi.so的路径即可具体见下(但本文是Ubuntu18.04的不用关心此问题)LoadModule wsgi_module "/usr/local/lib/python3.6/dist-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
验证mod_wsgi
编辑测试脚本vim /var/www/html/wsgi_test_script.py
def application(environ, start_response): status = '200 OK' output = b'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]配置wsgi
vim /etc/apache2/apache2.conf
# 最后加入WSGIScriptAlias /test_wsgi /var/www/html/wsgi_test_script.py
restart apache2
service apache2 restartcurl http://localhost/test_wsgiroot@5ee5ff2c92c7:/usr/bin# curl http://localhost/test_wsgiHello World!# 有输出代表成功!
二。通过wsgi跑django程序
cd /var/wwwdjango-admin startproject zq# config wsgi WSGIScriptAlias / /var/www/zq/zq/wsgi.pyWSGIPythonPath /var/www/zqRequire all granted # 注意WSGIPythonPath不配置的话,可能zq模块找不到# restart apache2service apache2 restart# testcurl http://localhost/
到此,相信大家对"apache配置python mod_wsgi的方法"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
配置
方法
内容
实际
环境
错误
会报
学习
验证
实用
更深
成功
不用
代表
兴趣
原理
命令
地方
基础
实用性
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
广州万易互联网科技有限公司
互联网科技网
蓝思科技飞鸽互联网
江苏根荣互联网科技
A股互联网金融科技公司
互联网扶贫科技
重庆互联网络科技
广州紫鲸互联网科技
中国互联网金融科技基金
互联网金融监管科技
华脉科技工业互联网产品
链环科技传统企业怎么转型互联网
华夏恒生科技与互联网科技
工业互联网等科技实现智能化赋能
伍佰万互联网科技怎么赚钱
富国互联网金融科技混合基金
神州科技互联网有限公司
艺电能源互联网科技有限公司招聘
互联网科技收购价值
数字科技和互联网金融哪个好
互联网金融科技
科技股互联网
科技和互联网公司
互联网科技英文
互联网科技生活的内容
中科明德北京互联网科技
区块链结合互联网科技
国产互联网科技公司
互联网时代高科技布局
广州三三互联网科技有限公司