首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >mod_wsgi中的Hello World

mod_wsgi中的Hello World
EN

Stack Overflow用户
提问于 2012-08-29 16:43:42
回答 1查看 24.1K关注 0票数 16

在使用mod_wsgi让我的flask应用程序在Apache上运行的过程中反复失败之后,我决定尝试运行hello world example。这是我的资料-

目录结构(我将apache的默认/var/www更改为~/public_html)

代码语言:javascript
复制
- public_html    
   - wsgi-scripts
      - test_wsgi.wsgi
   - test_wsgi
      - test_wsgi.wsgi

test_wsgi.wsgi文件

代码语言:javascript
复制
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]

    start_response(status, response_headers)

    return [output]

testwsgi配置文件(称为VirtualHost )-驻留在/etc/apache2/sites-enabled/

代码语言:javascript
复制
<VirtualHost *:80>
    DocumentRoot ~/public_html/test_wsgi

    <Directory ~/public_html/test_wsgi>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIScriptAlias /wsgi ~/public_html/wsgi-scripts/test_wsgi.wsgi

    <Directory ~/public_html/wsgi-scripts>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

当我尝试在浏览器上访问localhost/wsgi时,我得到了一个404not Found错误。我做错了什么?这是我第一次尝试在生产服务器上部署应用程序。到目前为止,我采用了使用Google App Engine的简单方法。我不能继续部署我的flask应用程序,直到它启动并运行。非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-29 18:51:14

您需要使用绝对路径,即不要使用~。这对我来说很好。

代码语言:javascript
复制
[mpenning@tsunami public_html]$ sudo cat /etc/apache2/sites-available/wsgi_test
<VirtualHost *:80>
    ServerName wsgihost
    DocumentRoot /home/mpenning/public_html
    WSGIScriptAlias / /home/mpenning/public_html/test.wsgi
</VirtualHost>
[mpenning@tsunami public_html]$

首先,我在/etc/hosts中设置了一个主机名,这样我就可以确保可以在查询中对该主机名进行多路复用……

代码语言:javascript
复制
[mpenning@tsunami public_html]$ grep wsgihost /etc/hosts
127.0.1.1       tsunami.foo.net  tsunami wsgihost
[mpenning@tsunami public_html]$

重新启动apache,并发出wget...

代码语言:javascript
复制
[mpenning@tsunami public_html]$ wget http://wsgihost/
--2012-08-29 05:50:26--  http://wsgihost/
Resolving wsgihost... 127.0.1.1
Connecting to wsgihost|127.0.1.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12 [text/plain]
Saving to: âindex.html.3â

100%[======================================>] 12          --.-K/s   in 0s

2012-08-29 05:50:26 (1.48 MB/s) - âindex.html.3â

[mpenning@tsunami public_html]$ cat index.html
Hello World![mpenning@tsunami public_html]$ #  <------
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12173971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档