Web2py nginx和域名

时间:2011-08-29 21:58:24

标签: python nginx web2py uwsgi

您好我正在运行web2py nginx和uwsgi,但我遇到了部署一个或多个域的问题。问题是服务器总是返回默认的欢迎应用程序,而不是我为域

指定的文件夹

非常感谢任何想法。这是我的nginx.conf文件(相关部分)

server {
    listen       80;
    server_name  www.cheer10s.com cheer10s.com;

    location / {
        uwsgi_pass     127.0.0.1:9001;
        include        uwsgi_params;
    }

    location /static {
        root   /opt/web2py/applications/cheer10s/;
    }
}

server {
    listen       443;
    server_name  www.cheer10s.com cheer10s.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 /opt/web2py/applications/cheer10s/;
    }
}

*欢呼声

1 个答案:

答案 0 :(得分:3)

这个位置:

location /static {
        root   /opt/web2py/applications/cheer10s/;
    }

只是对静态文件的重写,而不是对应用程序的重写,我想这是错误的,必须是:

location ~* /(\w+)/static/ {
           root /opt/web2py/applications/;
        }

上面的行只是NGINX直接在/ static文件夹下的服务器文件,不要触摸web2py。

使用uwsgi,这些行负责调用web2py

location / {
                uwsgi_pass      127.0.0.1:9001;
                include         uwsgi_params;
        }

并且必须在框架中定义路由器,而不是在nginx中定义。如果您想将 cheer10s 作为默认应用程序,请将routes.py放在您的web2py根文件夹中。看起来像这样:

routers = dict(

    # base router
    BASE = dict(
        default_application = 'cheer10s',
        domains = {
                'yourdomain.com' : 'cheer10s',
                'anotherdomain.com':'anotherapp'
                },
        applications = ['cheer10s','anotherapp','admin'],
        controllers = 'DEFAULT'
    ),
)

将上面的内容保存为web2py根文件夹中的routes.py并重新启动web2py,但不要忘记修复你的nginx conf。