【问题标题】:How to deploy web2py using nginx?如何使用 nginx 部署 web2py?
【发布时间】:2011-07-17 03:34:48
【问题描述】:

web2py 是一个很棒的 python 框架,它有很好的文档,包括几个部署recipes。然而,我想念的是使用 nginx 进行部署的方法(最好使用 uwsgi)。网上有一些不完整的注释(如here),但我找不到任何完整的独立指南。

【问题讨论】:

    标签: nginx web2py uwsgi


    【解决方案1】:

    好的,仔细查看我上面链接的 web2py 电子邮件列表,我发现 coplete 解决方案已经存在。我可以按照说明进行操作,感谢 pbreit 的精彩帖子,现在我的部署就像一个魅力(在空闲状态下仅使用 38MB RAM)与 nginx+uwsgi。

    这是我使用的部分(我只是剥离 fabfile.py 以在命令行上使用它) 注意:在哪里有 'put('....' 我使用 nano 文本编辑器来创建和编辑文件

    apt-get -y install build-essential psmisc python-dev libxml2 libxml2-dev python-setuptools
    cd /opt; 
    wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
    tar -zxvf uwsgi*
    mv /opt/uwsgi*/ /opt/uwsgi/
    cd /opt/uwsgi/; python setup.py install
    chown -R www-data:www-data /opt/uwsgi
    touch /var/log/uwsgi.log
    chown www-data /var/log/uwsgi.log
    apt-get -y install libpcre3-dev build-essential libssl-dev
    cd /opt; wget http://nginx.org/download/nginx-0.8.54.tar.gz
    cd /opt; tar -zxvf nginx*
    cd /opt/nginx*/; ./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module
    cd /opt/nginx*/; make
    cd /opt/nginx*/; make install
    adduser --system --no-create-home --disabled-login --disabled-password --group nginx
    cp /opt/uwsgi*/nginx/uwsgi_params /opt/nginx/conf/uwsgi_params
    
    wget https://library.linode.com/web-servers/nginx/installation/reference/init-deb.sh
    mv init-deb.sh /etc/init.d/nginx
    
    chmod +x /etc/init.d/nginx
    /usr/sbin/update-rc.d -f nginx defaults
    /etc/init.d/nginx start
    
    cd /opt/
    wget https://library.linode.com/web-servers/nginx/python-uwsgi/reference/init-deb.sh
    mv /opt/init-deb.sh /etc/init.d/uwsgi
    chmod +x /etc/init.d/uwsgi
    
    echo 'PYTHONPATH=/var/web2py/ MODULE=wsgihandler' >> /etc/default/uwsgi
    /usr/sbin/update-rc.d -f uwsgi defaults
    /etc/init.d/uwsgi start
    
    
    rm /opt/nginx/conf/nginx.conf
    # modify nginx.conf below and save it as /opt/nginx/conf/nginx.conf
    cd /opt/nginx/conf; openssl genrsa -out server.key 1024
    cd /opt/nginx/conf; openssl req -batch -new -key server.key -out server.csr
    cd /opt/nginx/conf; 
    openssl x509 -req -days 1780 -in server.csr -signkey server.key -out server.crt
    
    /etc/init.d/nginx restart 
    

    nginx.conf

         user www-data;
         worker_processes  4;
    
         events {
             worker_connections  1024;
    
         }
    
         http {
             include       mime.types;
             default_type  application/octet-stream;
             keepalive_timeout  2;
             sendfile        on;
             #tcp_nopush     on;
             tcp_nodelay     on;
             gzip  on;
             server {
                 listen       80;
                 server_name  example.com www.example.com;
    
                 location / {
                     uwsgi_pass 127.0.0.1:9001;
                     include uwsgi_params;
                 }
    
                 location /static {
                     root /var/web2py/applications/init/;
                 }
             }
    
      # HTTPS server
         server {
             listen       443;
             server_name  www.example.com example.com;
             ssl                  on;
             ssl_certificate      /opt/nginx/conf/server.crt;
             ssl_certificate_key  /opt/nginx/conf/server.key;
    
             location / {
                 uwsgi_pass 127.0.0.1:9001;
                 include uwsgi_params;
                 uwsgi_param     UWSGI_SCHEME $scheme;
             }
    
    
       location /static {
                 root /var/web2py/applications/init/;
             }
         }
    
     }
    

    源自web2py email list 在this Linode 帖子的帮助下

    【讨论】:

    • 请注意这个配置文件有一些路径重新映射...似乎假设一个初始化应用程序。
    • @massimo:为了支持多个应用程序应该做些什么改变?
    • "chown -R www-data:www-data /opt/uwsgi" 是一个严重的安全问题。
    • @fsaintjacques - 请提供一些指向 why 的链接,这是一个“严重的安全问题”,更重要的是,建议如何 更好地做到这一点将不胜感激。 (注意:我不不同意,只是要求提供“不要那样做”之外的有用帖子。)
    【解决方案2】:
    猜你喜欢
    • 2012-01-13
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2021-11-11
    相关资源
    最近更新 更多