我有一个在域(例如 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/;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用 example.com/test/ url 访问该应用程序,但尽管有别名,静态文件仍无法加载(给出 404 错误)。
我怎样才能解决这个问题?
更新:按照说明添加整个服务器块
server {
listen *:80 default_server; ## listen for ipv4; this line is default and implied
#listen [::]:80; # listen for ipv6
root /home/hrishi/www/example.com/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com;
# Logging
access_log …
Run Code Online (Sandbox Code Playgroud)