加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

UWSGI和NGINX for Ubuntu 11.10上的Python应用程序

发布时间:2020-12-13 21:22:33 所属栏目:Nginx 来源:网络整理
导读:我试图找到一种最佳方式来设置我的服务器以使用NGINX和UWSGI来为python应用程序提供服务.到目前为止,以下工作: 初始设置: sudo apt-get install nginx uwsgi uwsgi-plugin-http uwsgi-plugin-python python-setuptoolseasy_install pippip install web.py

我试图找到一种最佳方式来设置我的服务器以使用NGINX和UWSGI来为python应用程序提供服务.到目前为止,以下工作:

初始设置:

sudo apt-get install nginx uwsgi uwsgi-plugin-http uwsgi-plugin-python python-setuptools

easy_install pip

pip install web.py

在/ etc / nginx的/网站可用/默认:

server {
    listen 80;
    server_name localhost;
    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:9090;
    }
}

然后我有一个基本的myapp.py(位置对当前设置无关紧要):

import web

urls = (
    '/','index'
)

app = web.application(urls,globals())

class index:
    def GET(self):
        return "Hello from Web.py!"

application = app.wsgifunc()

然后我可以发出以下命令,一切正常:

sudo service nginx restart

uwsgi --plugins http,python -s 127.0.0.1:9090 myapp

所以它有效,但它不是很漂亮.我注意到当我用apt-get安装UWSGI时,创建了两个目录:/ etc / uwsgi / apps-available和/ etc / uqsgi / apps-enabled.这符合运行NGINX或Apache的debian服务器的惯例,只适用于应用而非站点.

这将是非常棒的:我希望能够将应用程序配置放入可用的应用程序(根据需要在应用程序中创建符号链接)并让UWSGI服务选择它们.但我不知道从哪里开始.我在应用程序中放置了哪些配置文件? NGINX配置对于传递到uwsgi服务而不是传递到我之前发出的命令创建的套接字是什么样的?

最佳答案
我搞定了!这是我做的:

创建/etc/uwsgi/apps-available/myapp.xml:

发出以下命令:

ln -s /etc/uwsgi/apps-available/myapp.xml /etc/uwsgi/apps-enabled/myapp.xml
sudo service uwsgi restart

更新了/ etc / nginx / sites-available / default:

server {
    listen 80;
    server_name localhost;
    location / {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi-myapp.sock;
    }
}

重启NGINX:

sudo service nginx restart

一切都是金色的!显然,以上是一个非常简单的配置,应该在投入生产之前查看可用的UWSGI和NGINX选项.

UWSGI配置中还有< socket> 127.0.0.1:9090< / socket>然后保留NGINX配置.

最后需要注意的是:UWSGI支持多种配置格式:(INI,XML和YAML).我最初尝试过YAML,但服务器无法启动所以我尝试了XML,一切正常.

编辑:

我刚尝试了INI配置,它也运行良好.作为上述XML文件的等效INI文件如下:

[uwsgi]
socket = /tmp/uwsgi-myapp.sock
plugins = http,pythong
chdir = /path/to/directory/containing/python/app
module = myapp

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读