下面是完整的攻略.首先,需要安装flup和Nginx,然后配置Nginx并使用flup搭建Python环境.
安装flup:
$ pip install flup
安装Nginx:
$ sudo apt-get update
$ sudo apt-get install nginx
$ sudo vim /etc/nginx/sites-available/default
在该文件中,查找以下内容并修改为:
server {
}
}
挂起Nginx服务器:
$ sudo systemctl stop nginx.service
启动Nginx服务器:
$ sudo systemctl start nginx.service
在你的Web应用程序目录中创建"hello.py"文件,并在其中添加以下代码:
#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Hello, World! "
print "Hello, World!
"
设置文件权限以便为Python脚本提供执行权限
$ chmod +x hello.py
在Nginx配置文件中添加以下内容:
location /hello {
}
}
安装CGI模块:
$ sudo apt-get install libnginx-mod-http-fastcgi
示例一使用CGI方式配置了Nginx服务器来托管Python脚本.
在你的Web应用程序目录中创建"hello_fastcgi.py"文件,并在其中添加以下代码:
#!/usr/bin/python
import sys
sys.path.insert(0, "/path/to/your/application")
from flup.server.fcgi import WSGIServer
def app(environ, start_response):
return ["Hello, World! Hello, World!
"]
WSGIServer(app).run()
基于你的需要,启动文本文本运行FastCGI服务器
$ python /path/to/your/application/hello_fastcgi.py
尽管Python应用程序可以工作,但我们在远程访问时希望使用Nginx,所以呢,我们需要配置Nginx.
location /hello_fastcgi {
fastcgi_pass 12⑦0.0.1:8000;
}
示例二使用FastCGI方式配置了Nginx服务器来托管Python脚本.
现在你的Nginx服务器已经配置好,可以使用flup轻松地为Python脚本提供Web服务了.
以上就是土嘎嘎小编为大家整理的Windows系统下使用flup搭建Nginx和Python环境的方法相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!