Web2py nginx 和域

发布于 2024-12-01 18:34:18 字数 874 浏览 2 评论 0原文

您好,我正在运行 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/;
    }
}

*干杯

Hello I am running web2py nginx and uwsgi but I am running into an issue deploying 1 or more domains. The issue is the server is always returning the default welcome application and not the folder I specify for a domain

Any ideas are greatly appreciated. Here is my nginx.conf file (the relevant parts)

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/;
    }
}

*cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城空念 2024-12-08 18:34:18

这个位置:

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 根文件夹中的 paths.py 并重新启动 web2py,但不要忘记修复你的 nginx 配置。

This location:

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

is only a rewrite for static files, not for apps, and I guess it is wrong, must be:

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

The line above will just server files under /static folder directly by NGINX do not touching web2py for it.

with uwsgi, this lines are responsible to call web2py

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

and the router must be defined in the framework, not in nginx. if you want to cheer10s to be the default application, place routes.py in your web2py root folder. looking like this:

routers = dict(

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

save the content above as routes.py in web2py root folder and restart web2py, but dont forget to fix your nginx conf.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文