webpy加apache2搭建简单网站

本文详细介绍如何使用Apache2和mod_wsgi在Ubuntu上部署PythonWeb应用。包括安装必要软件包、配置虚拟主机、设置目录权限及运行示例应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

apt-get install apache2 

sudo apt-get install libapache2-mod-wsgi

编辑/etc/apache2/sites-available/default,在<VirtualHost *:80> 下加入:

  ServerName webapp.com  
  DocumentRoot /home/webapp  
  <Directory /home/webapp>  
      Order allow,deny  
      Allow from all  
  </Directory>  
  Alias /static /home/webapp/static  #网站
  Alias /favicon.ico /home/webapp/static  #网站图标
  WSGIDaemonProcess webapp.com processes=2 threads=15 display-name=%{GROUP}  
  WSGIProcessGroup webapp.com  #网站名称
  WSGIScriptAlias / /home/webapp/index.py  #主页

然后在/home/webapp下面写个index.py:
import web  
urls = (  
    '/', 'index',  
    '/test', 'index1'  
    )  
  
app = web.application(urls, globals(), autoreload=True)  
class index:  
    def GET(self):  
        return 'hello world!'  
class index1:  
    def GET(self):  
        return 'hello test!'  
  
application = app.wsgifunc()  
  
      
if __name__ == "__main__":  
    app.run()  

然后命令行:

service apache2 restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值