2012-08-29 32 views
16

Sau khi thất bại nhiều lần trong nhiệm vụ của tôi để có được ứng dụng bình của tôi chạy trên Apache sử dụng mod_wsgi Tôi quyết định thử chạy hello world example. Dưới đây là những gì tôi có -Xin chào thế giới trong mod_wsgi

mục Structure (Tôi đã thay đổi apache mặc định /var/www để ~/public_html)

- public_html  
    - wsgi-scripts 
     - test_wsgi.wsgi 
    - test_wsgi 
     - test_wsgi.wsgi 

tập tin test_wsgi.wsgi

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] 

tập tin VirtualHost cấu hình (gọi tắt là testwsgi) - cư trú này in /etc/apache2/sites-enabled/

<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> 

Khi tôi thử truy cập localhost/wsgi trên trình duyệt, tôi nhận được lỗi 404 Not Found. Tôi đang làm gì sai? Đây là lần đầu tiên tôi cố gắng triển khai một ứng dụng trên một máy chủ sản xuất. Cho đến bây giờ, tôi đã sử dụng Google App Engine một cách dễ dàng. Tôi không thể tiếp tục triển khai ứng dụng bình của mình cho đến khi nó hoạt động. Cảm ơn rất nhiều!

Trả lời

12

Bạn cần sử dụng đường dẫn tuyệt đối, ví dụ: không sử dụng ~. Đây hoạt động tốt đối với tôi ...

[[email protected] 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> 
[[email protected] public_html]$ 

Trước tiên tôi thiết lập một hostname trong /etc/hosts, vì vậy tôi có thể đảm bảo rằng tôi có thể MUX trên hostname trong truy vấn ...

[[email protected] public_html]$ grep wsgihost /etc/hosts 
127.0.1.1  tsunami.foo.net tsunami wsgihost 
[[email protected] public_html]$ 

Khởi động lại apache và phát hành một wget ...

[[email protected] 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â 

[[email protected] public_html]$ cat index.html 
Hello World![[email protected] public_html]$ # <------ 
Các vấn đề liên quan