【问题标题】:Nginx serving "location /" but not serving "location /project-name/" specified in /etc/nginx/sites-available/ config fileNginx 提供“位置/”但不提供 /etc/nginx/sites-available/ 配置文件中指定的“位置/项目名称/”
【发布时间】:2020-05-21 13:10:04
【问题描述】:

我是 Nginx 的新手,我正在使用它通过以下方式配置我的网站:

  1. 请求http://xx.xx.xx.xx/ -> Nginx 应该提供来自 /var/www/html 目录的静态 html 文件

  2. 请求http://xx.xx.xx.xx/project-name/ -> Nginx 应该通过 WSGI(使用 UNIX 套接字)调用 Python Flask 应用程序

这是我的 /etc/nginx/sites-available/project-name 文件:

server {
   listen 80:
   server_name xx.xx.xx.xx;

   root /var/www/html;

   location / {
      try_files $uri $uri/ =404;
   }

   location /project-name/ {
      include wsgi_params;
      uwsgi_pass unix:/home/user-name/project-name/project-name.sock
   }
}

当我在浏览器中输入http://xx.xx.xx.xx 时,我会看到默认的 Nginx 页面。但是如果我在浏览器中输入http://xx.xx.xx.xx/project-name/,我会得到一个 404 (Requested URL not found) 错误。

现在的问题是,如果我将“位置 /”指向 Flask 应用程序,如下所示,那么 Flask 应用程序工作正常并返回正确的页面(但 http://xx.xx.xx.xx 调用 Flask 应用程序,我无法提供服务直接来自 Nginx 的静态 html 文件):

server {
   listen 80:
   server_name xx.xx.xx.xx;

   location / {
      include wsgi_params;
      uwsgi_pass unix:/home/user-name/project-name/project-name.sock
   }
}

我错过了一些简单的东西吗?

【问题讨论】:

    标签: nginx flask


    【解决方案1】:

    这是一个简单的疏忽。

    在我的 Flask 应用程序中,我处理的是路由“/”而不是“/project-name/”。

    【讨论】:

      猜你喜欢
      • 2017-06-20
      • 2018-12-08
      • 2014-01-26
      • 2011-01-15
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      相关资源
      最近更新 更多