nginx 无法向 Flask 提供静态文件

nginx 无法向 Flask 提供静态文件

我尝试过其他帖子中的许多解决方案,但似乎没有什么对我有用,我总是得到一个 404 错误,当试图让nginx提供我的静态文件烧瓶应用程序。在我的本地主机服务器上,flask 无法从另一个内部软件静态目录接收静态文件。

我正在运行一个 gunicorn 服务器本地主机:7777并在尝试运行我的网页上的某个页面时收到以下错误:


127.0.0.1/:210     GET http://127.0.0.1:7777/Website/visualization/static/js/main.3a9af0a7.chunk.js net::ERR_ABORTED 404 (NOT FOUND)

manifest.json:1     GET http://127.0.0.1:7777/Website/visualization/manifest.json 404 (NOT FOUND)

manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.

我的/etc/nginx/nginx.conf 文件有一个块,用于将上述文件提供给 Flask:

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
        
    access_log /home/antho/Website_Stack/server/nginx-access.log;
        error_log /home/antho/Website_Stack/server/nginx-error.log;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
        
        location ~ ^/Website/visualization/reference/(\S+)$ {
            alias /home/antho/Website_Stack/server/opt/web/sc_web/templates/JBrowse/reference/$1;
        }

        location ~ /visualization/5c9f1639441ae475a829.worker.js {
            alias /home/antho/Website_Stack/server/opt/web/sc_web/templates/JBrowse/5c9f1639441ae475a829.worker.js;
        }

        location ~ /visualization/manifest.json {
            alias /home/antho/Website_Stack/server/opt/web/sc_web/templates/JBrowse/manifest.json;
        }
        
        location ~ /visualization/config.json {
            alias /home/antho/Website_Stack/server/opt/web/sc_web/templates/JBrowse/config.json;
        }
        
        location /Website/visualization/static/ {
            alias /home/antho/Website_Stack/server/opt/web/sc_web/templates/JBrowse/static/;
        }

        location /Website/visualization/vcf/{
            alias /home/antho/Website_Stack/server/opt/web/sc_web/templates/JBrowse/vcf/;
        }
        
    location / {
        proxy_pass http://127.0.0.1:7777;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    error_page 404 /404.html;
        location = /404.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
   }

我的应用程序/home/antho/Website_Stack/server/opt/web/sc_web与网站的其余文件位于一起。

我已确保所有文件都具有正确的权限,我向这些文件授予了所有我可以授予的权限,以确保:

antho@x005:~/Website_Stack/server/opt/web/sc_web/templates/JBrowse$ ls -l
total 17672
-rwxrwxrwx 1 nginx nginx  3254625 Aug 22 01:29 5c9f1639441ae475a829.worker.js
-rwxrwxrwx 1 nginx nginx    12889 Aug 22 01:29 5c9f1639441ae475a829.worker.js.LICENSE.txt
-rwxrwxrwx 1 nginx nginx 11890441 Aug 22 01:29 5c9f1639441ae475a829.worker.js.map
-rwxrwxrwx 1 nginx nginx     1949 Aug 22 01:29 asset-manifest.json
-rwxrwxrwx 1 nginx nginx   378219 Aug 22 01:29 config.DB_V1.0.1.json
-rwxrwxrwx 1 nginx nginx   386923 Aug 22 01:29 config.DB_V1.0.json
-rwxrwxrwx 1 nginx nginx   644276 Aug 22 01:29 config.json
-rwxrwxrwx 1 nginx nginx   418838 Aug 22 01:29 config.V1.1.json
-rwxrwxrwx 1 nginx nginx   393995 Aug 22 01:29 config.V1.1.old.json
-rwxrwxrwx 1 nginx nginx   617012 Aug 22 01:29 config.V1.2.json
-rwxrwxrwx 1 nginx nginx    15086 Aug 22 01:29 favicon.ico
-rwxrwxrwx 1 nginx nginx     8167 Sep 28 16:34 index_bak.html
-rwxrwxrwx 1 nginx nginx     8063 Sep 28 16:40 index.html
-rwxrwxrwx 1 nginx nginx      294 Sep 27 09:58 manifest.json
-rwxrwxrwx 1 nginx nginx       27 Sep 28 14:35 package-lock.json
-rwxrwxrwx 1 nginx nginx     3521 Aug 22 01:29 precache-manifest.821b6df26bf08d62dbdfb33a979d34ae.js
drwxrwxrwx 3 nginx nginx     4096 Aug 22 01:30 reference
-rwxrwxrwx 1 nginx nginx       57 Aug 22 01:30 robots.txt
-rwxrwxrwx 1 nginx nginx     1185 Aug 22 01:30 service-worker.js
drwxrwxrwx 5 nginx nginx     4096 Aug 22 01:30 static
drwxrwxrwx 7 nginx nginx     4096 Aug 22 01:30 test_data
-rwxrwxrwx 1 nginx nginx       45 Oct  6 13:47 test.html
drwxrwxrwx 4 nginx nginx     4096 Aug 22 01:31 vcf

nginx 错误和访问日志没有提供任何信息。

我尝试过许多解决方案来修复静态文件的路径,使用 root 和 alias 选项,但都无法解决这个问题。所有“网站”实例都是实际网站的替代名称。

这是我第一次尝试软件开发,已经开始想不出什么可以尝试的想法了。如果我需要添加任何内容,请告诉我。

谢谢你的帮助!

最好的,安东尼·谢伊。

相关内容