문제

I'm having some trouble configuring nginx to work with Python3.2. I'm also struggling to find anything resembling a decent tutorial on the subject. I did however find a decent tutorial on getting nginx to play nice with Python2.7. My thought process was that since uwsgi works with plugins it should be a relatively simple exercise to follow the Python2.7 tutorial and just swap out the python plugin.

Here is the tutorial I followed to get a basic Hello World site working: https://library.linode.com/web-servers/nginx/python-uwsgi/ubuntu-12.04-precise-pangolin

/etc/uwsgi/apps_available/my_site_url.xml looks like:

<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/my_site_urlmy_site_url.socket</socket>
    <pythonpath>/srv/www/my_site_url/application/</pythonpath>
    <app mountpoint="/">
        <script>wsgi_configuration_module</script>
    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>

Once everything was working installed uwsgi-plugin-python3 via apt-get. ls -l /usr/lib/uwsgi/plugins/ now outputs:

-rw-r--r-- 1 root root 142936 Jul 17  2012 python27_plugin.so
-rw-r--r-- 1 root root 147192 Jul 17  2012 python32_plugin.so
lrwxrwxrwx 1 root root     38 May 17 11:44 python3_plugin.so -> /etc/alternatives/uwsgi-plugin-python3
lrwxrwxrwx 1 root root     37 May 18 12:14 python_plugin.so -> /etc/alternatives/uwsgi-plugin-python

Changing python to python3 or python32 in my_site_url.xml has the same effect, ie:

  • The hello world page takes ages to load (it was effectively instantanious before) and then comes up blank
  • My site's access log records access
  • my site's error log records no new error
  • /var/log/uwsgi/app/my_site_url.log records the following:

    [pid: 4503|app: 0|req: 1/2] 192.168.1.5 () {42 vars in 630 bytes} [Sun May 19 10:49:12 2013] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 65 bytes (1 switches on core 0)

so My question is:

How can I correctly configure this app to work on Python3.2

도움이 되었습니까?

해결책

The listed tutorial has the following application code:

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]

This is incompatable with python3.2 because it expects a bytes object. Replacing the application function with the following fixes things:

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return b"Hello World"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top