如何在Nginx+;如果应用程序映射到子目录,则烧瓶设置

如何在Nginx+;如果应用程序映射到子目录,则烧瓶设置,nginx,flask,Nginx,Flask,我在一个域(比如example.com)上运行一个基本的html站点,我想在一个子目录(比如example.com/test)中运行一个flask应用程序 flask应用程序正在使用默认flask开发服务器在端口5433上运行 我使用了以下nginx配置来实现这一点 location /test { rewrite /test(.*) $1 break; proxy_pass http://localhost:5433; prox

我在一个域(比如example.com)上运行一个基本的html站点,我想在一个子目录(比如example.com/test)中运行一个flask应用程序 flask应用程序正在使用默认flask开发服务器在端口5433上运行

我使用了以下nginx配置来实现这一点

location /test {
           rewrite /test(.*) $1 break;
           proxy_pass http://localhost:5433;
           proxy_redirect     default;
           proxy_set_header   Host             $host;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }

    location /static/{
    alias /home/hrishi/www/example.com/test/app/static/;
    }
我可以使用example.com/test/url访问该应用程序,但是静态文件无法加载(给出404错误),尽管有别名


我怎样才能解决这个问题

这是因为有一个额外的

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
expires           max;
}

在服务器块内部,我删除了它,并通过

chmod -R 664 /the/path/to/static/dir
chmod a+X /the/path/to/static/dir

它就像一个符咒

这不是子域。我的子域在你的域名之前开始。在您的情况下,它将是test.example.com。在这种情况下,它永远不会起作用。