基于python的动态虚拟主机

1.安装python模块

dnf install python3-mod_wsgi -y

2.添加脚本

vim /var/www/cgi-bin/helloworld.wsgi

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

3.添加配置文件内容

配置文件:vim /etc/httpd/conf.d/vhost.conf

<virtualhost 192.168.233.139:80>

servername www.haha.com

WSGIScriptAlias / /var/www/cgi-bin/helloworld.wsgi

</virtualhost>

4.域名映射

vim /etc/hosts

192.168.233.139 www.haha.com

5.重启服务

systemctl restart httpd

6.访问内容

curl http://www.haha.com

相关推荐
程序员-Benothing1 小时前
Linux文件查看与编辑:cat、less、tail、vim快速入门
linux·运维·服务器
陈陈CHENCHEN12 小时前
【Linux】服务器根目录磁盘扩容操作记录
linux·运维·服务器
沸速存储14 小时前
AI 机器人靠哪些内存与存储驱动整机运行?
服务器·科技·嵌入式硬件·电脑
fengyehongWorld15 小时前
Linux squid搭建基础代理服务器
linux·运维·服务器
Cx330❀16 小时前
【Linux网络】网络层 IP 协议:从网段划分到内核源码解析
大数据·linux·服务器·网络·tcp/ip·性能优化·langchain
一技安身17 小时前
【信创】docker-26.0.2.tgz 原理 + 完整安装
linux·运维·服务器
郝学胜-神的一滴18 小时前
Effective Python 条款 13:善用星号解包,告别下标切片拆分的坑
服务器·开发语言·数据结构·python·程序人生·pycharm
智购无人售货机厂家19 小时前
2026自动售货机品类拓展逻辑:从饮料零食到鲜食药品文创的工程实践~YH
服务器·人工智能·单片机·线性代数·矩阵
国际云,接待19 小时前
华为云 ECS 怎么选规格:从用户地域、CPU/内存比、PPS 和云硬盘性能做购买前容量判断
服务器
国际云,接待19 小时前
华为云 CBR 备份不是点一下就完事:用恢复演练验证 ECS 的 RPO、RTO 和跨区域容灾
服务器