Web2py、nginx 和域名
你好,我正在使用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 个回答
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'
),
)
把上面的内容保存为 routes.py 放在 web2py 根文件夹里,然后重启 web2py,但别忘了修正你的 nginx 配置。