【问题标题】:nginx proxy_pass to flask works while /static fail to find jquerynginx proxy_pass 到烧瓶工作,而 /static 找不到 jquery
【发布时间】:2018-10-25 19:54:31
【问题描述】:

我是一个 nginx 的菜鸟(以及 apache 和 php ...)

我有这个可以正常工作的烧瓶应用程序:

http://127.0.0.1:5000
以及外部来自
http://myhost.com:5000

我想使用来自
myhost.com/rest_1
为其他人腾出空间休息,例如 myhost.com/rest_2 .. 3 等等。
该应用位于
/opt/rest_1
并使用它的 /static 文件夹中的一些资源,例如 css 和 jquery。

我有这个
/etc/nginx/sites-available/rest_1.conf

server {
   listen 80;
   listen [::]:80;
   server_name myhost.com;
   server_name_in_redirect off;

   location /rest_1 {
            rewrite ^/rest_1(.*) /$1 break;
            proxy_pass http://127.0.0.1:5000/;
   }}

它是指向已启用网站的链接。
nginx 重新启动并重新加载,没有错误。
其他配置是安装时的默认配置。

当我尝试连接时

myhost.com/rest_1

我可以看到一个不完整的页面部分工作,查看 nginx 日志:
/var/log/nginx/error.log

*8 open() "/usr/share/nginx/html/static/w3.css" failed (2: No such file or directory), client: xx.xx.xx.xx, server: myhost.com, request: "GET /static/w3.css HTTP/1.1", host: "myhost.com", referrer: "http://myhost.com/rest_1"

所以,我很清楚 '/usr/share/nginx/html/' 是从其他地方获得的......并且该文件夹也应该有一个正确的名称(我是菜鸟!!)

如何告诉引擎重定向到正确的路径
/opt/rest_1
取回所有/静态功能?

操作系统:ubuntu 服务器 16.04
nginx:1.10.3

谢谢。

【问题讨论】:

    标签: nginx url-redirection proxypass


    【解决方案1】:

    因为您没有为静态内容设置一个位置资源。您的应用程序从 de 根文件夹引用 CSS,而不是从 rest_1。

    您的 CSS 调用是 http://myhost.com/STATIC,因此它与您设置的位置不匹配并在默认值内尝试。

    所以你可以在你的应用程序中解决它,或者你可以在你的 nginx 中设置它,如下所示:

       location /static {
           root /opt/rest_1;
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      相关资源
      最近更新 更多