Skip to main content
 首页 » 编程设计

python之Web2py nginx 和域

2024年09月03日3598°冷暖

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

非常感谢任何想法。这是我的 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/; 
    } 
} 

*干杯

请您参考如下方法:

这个位置:

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。