跑步"独立" nginx

时间:2017-09-26 22:42:23

标签: python nginx

我想运行python脚本,使用nginx输出类似的格式:

content-type: text/plain;charset=utf-8
content-length: 14
Hello, world!

他们还通过查看accept-encoding请求标头来内部处理压缩 如何使用nginx运行这些脚本? 我正在用这个把头撞到墙上。

使用apache,您可以:

#/etc/apache2/python_exec.include
<Directory "/var/www/localhost">
    Options +ExecCGI
    AddHandler cgi-script .py
    Require all granted
</Directory>

然后将其包含在<VirtualHost>块中,并为.py文件提供执行权限。

/var/www/localhost/hello.py生成示例输出:

#!/usr/bin/env python3
import sys
headers = [ 'content-type: text/plain;charset=utf-8' ]
body = b'Hello, world!\n' #this could be compressed, too, with the according information appended to headers
headers.append('content-length: {}'.format(len(body)))
sys.stdout.buffer.write('\r\n'.join(headers + ['', '']).encode('utf-8'))
sys.stdout.buffer.write(body)

0 个答案:

没有答案