2012-08-29 14 views
16

mod_wsgi का उपयोग करके अपाचे पर चलाने के लिए मेरे फ्लास्क एप्लिकेशन को प्राप्त करने के लिए मेरी खोज में बार-बार विफल होने के बाद मैंने hello world example चलाने का प्रयास करने का निर्णय लिया। यहाँ मैं क्या है -mod_wsgi में हैलो वर्ल्ड

निर्देशिका संरचना

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

test_wsgi.wsgi फ़ाइल (मैं अपाचे डिफ़ॉल्ट ~/public_html को /var/www बदल)

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] 

VirtualHost विन्यास फ़ाइल (बुलाया testwsgi) - यह बसता था /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> 

जब मैं ब्राउज़र पर localhost/wsgi पर जाने का प्रयास करता हूं तो मुझे 404 नहीं मिला त्रुटि मिलती है। मैं क्या गलत कर रहा हूं? यह पहली बार है जब मैं एक उत्पादन सर्वर पर एक ऐप तैनात करने की कोशिश कर रहा हूं। अब तक मैंने Google App Engine का उपयोग करने का आसान तरीका लिया है। जब तक यह ऊपर और चलने तक मैं अपने फ्लास्क ऐप को तैनात करने के लिए आगे नहीं बढ़ सकता। आपका बहुत बहुत धन्यवाद!

उत्तर

12

आपको एक पूर्ण पथ का उपयोग करने की आवश्यकता है, यानी ~ का उपयोग न करें। यह मेरे लिए ठीक काम करता है ...

[[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]$ 

सबसे पहले मैं /etc/hosts में एक होस्ट नाम की स्थापना की है, इसलिए मैं यह सुनिश्चित कर सकता है कि मैं क्वेरी में होस्ट नाम पर mux कर सकते हैं ...

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

पुनः प्रारंभ अपाचे , और एक 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]$ # <------ 
संबंधित मुद्दे