tuna/mirror-web

子目录的url与status该如何显示

CHEN-Technology opened this issue · 16 comments

image

您好,请问子目录的url与status该如何显示,我在html中找到了它们但不知该如何传入数据

这个需要使用 njs 搭配 fancyindex,方可显示目录浏览内容。

请参考:
#233 (comment)

我加入了njs模块但是启动nginx报错unknown directive "js_include",经过查找是在njs0.7.1中被js_import代替。
但是我在完成替换后再次启动nginx报错nginx: [emerg] cannot extract export name from file path "/data/mirrors/static/njs/all.njs", use extended "from" syntax in /etc/nginx/nginx.conf:82
我并未查找到关于此问题的答案,求解

请改用:

js_import fancyIndexRender from fancy_index.njs;
location = /fancy-index/before {
         js_content fancyIndexRender.fancyIndexBeforeRender;
}
location = /fancy-index/after {
        js_content fancyIndexRender.fancyIndexAfterRender;
}

请参考:#345 (comment)

是的,解决了终端命令的报错,但是网页报错crbug/1173575, non-JS module files deprecated.
这似乎是njs模块的问题,它不支持非js模块了
image

您好,你看到的问题是页面没有正确载入导致的。您可以直接用 curl 发出请求,并观察返回结果是否存在异常。

以下是返回的结果

C:\Users\Administrator>curl -s -v -X POST -H "text/html" http://10.1.10.111/blender/
*   Trying 10.1.10.111:80...
* Connected to 10.1.10.111 (10.1.10.111) port 80 (#0)
> POST /blender/ HTTP/1.1
> Host: 10.1.10.111
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Server: nginx/1.24.0
< Date: Thu, 05 Oct 2023 00:08:47 GMT
< Content-Type: text/html
< Content-Length: 153
< Connection: keep-alive
<
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.24.0</center>
</body>
</html>
* Connection #0 to host 10.1.10.111 left intact

找到原因了,是

	fancyindex_header /fancy-index/before;
	fancyindex_footer /fancy-index/after;

中缺少.html

但仍旧如此
image

这是我的nginx,conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

load_module modules/ngx_http_js_module.so;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

	map $http_user_agent $isbrowser {
  		default 0;
 	 "~*validation server" 0;
 	 "~*mozilla" 1;
	}

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /data/mirrors;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

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

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
	
	location /static/tunasync.json {
                	proxy_pass http://localhost:12345/jobs;
      	}

	fancyindex_header /fancy-index/before.html;
	fancyindex_footer /fancy-index/after-legacy.html;
	fancyindex_exact_size off;
	fancyindex_time_format "%Y-%m-%d %H:%M";
	fancyindex_name_length 256;
	js_path /data/mirrors/static/njs;
	js_import fancyIndexRender from /data/mirrors/static/njs/fancy_index.njs;


	location /fancy-index {
		internal;
		root /data/mirrors;
		subrequest_output_buffer_size 100k;
		location = /fancy-index/before {
			js_content fancyIndexRender.fancyIndexBeforeRender;
 		}
		location = /fancy-index/after {
			js_content fancyIndexRender.fancyIndexAfterRender;
		}
	}

	location / {
		root /data/mirrors;
		fancyindex on;
	}
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#        location = /404.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#        location = /50x.html {
#        }
#    }

}

fancyindex_header 应为 /fancy-index/before (不带 .html)。

使用 POST 请求 nginx 的静态文件会得到 403 的返回码是正常现象,并无异常。

那该如何解决这个问题
#397 (comment)

您需要具体描述出现的问题。

网页子目录无法访问

C:\Users\Administrator>curl -s -v -X POST -H "text/html" http://10.1.10.111/blender/
*   Trying 10.1.10.111:80...
* Connected to 10.1.10.111 (10.1.10.111) port 80 (#0)
> POST /blender/ HTTP/1.1
> Host: 10.1.10.111
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Server: nginx/1.24.0
< Date: Fri, 06 Oct 2023 01:15:30 GMT
< Content-Type: text/html
< Content-Length: 153
< Connection: keep-alive
<
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.24.0</center>
</body>
</html>
* Connection #0 to host 10.1.10.111 left intact
C:\Users\Administrator>curl -s -v -X GET -H "text/html" http://10.1.10.111/blender/
*   Trying 10.1.10.111:80...
* Connected to 10.1.10.111 (10.1.10.111) port 80 (#0)
> GET /blender/ HTTP/1.1
> Host: 10.1.10.111
> User-Agent: curl/8.0.1
> Accept: */*
>
* Empty reply from server
* Closing connection 0

image
image

这是nginx的错误日志

2023/10/06 09:17:48 [notice] 98851#98851: using the "epoll" event method
2023/10/06 09:17:48 [notice] 98851#98851: nginx/1.24.0
2023/10/06 09:17:48 [notice] 98851#98851: built by gcc 11.4.1 20230605 (Red Hat 11.4.1-2) (GCC) 
2023/10/06 09:17:48 [notice] 98851#98851: OS: Linux 5.14.0-370.el9.x86_64
2023/10/06 09:17:48 [notice] 98851#98851: getrlimit(RLIMIT_NOFILE): 1024:524288
2023/10/06 09:17:48 [notice] 98852#98852: start worker processes
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98853
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98854
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98855
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98856
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98857
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98858
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98859
2023/10/06 09:17:48 [notice] 98852#98852: start worker process 98860
2023/10/06 09:17:51 [error] 98854#98854: *2 open() "/data/mirrors/fancy-index/after-legacy" failed (2: No such file or directory), client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/after-legacy", host: "10.1.10.111"
2023/10/06 09:17:51 [error] 98854#98854: *2 js exception: TypeError: cannot get property "match" of undefined
    at anonymous (/usr/share/nginx/site/static/njs/markup.min.njs:6)
    at anonymous (/usr/share/nginx/site/static/njs/fancy_index.njs:13)
 while sending response to client, client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/before.html", host: "10.1.10.111"
2023/10/06 09:17:51 [error] 98859#98859: *1 open() "/data/mirrors/fancy-index/after-legacy" failed (2: No such file or directory), client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/after-legacy", host: "10.1.10.111"
2023/10/06 09:17:51 [error] 98859#98859: *1 js exception: TypeError: cannot get property "match" of undefined
    at anonymous (/usr/share/nginx/site/static/njs/markup.min.njs:6)
    at anonymous (/usr/share/nginx/site/static/njs/fancy_index.njs:13)
 while sending response to client, client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/before.html", host: "10.1.10.111"
2023/10/06 09:17:51 [error] 98855#98855: *3 open() "/data/mirrors/fancy-index/after-legacy" failed (2: No such file or directory), client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/after-legacy", host: "10.1.10.111"
2023/10/06 09:17:51 [error] 98855#98855: *3 js exception: TypeError: cannot get property "match" of undefined
    at anonymous (/usr/share/nginx/site/static/njs/markup.min.njs:6)
    at anonymous (/usr/share/nginx/site/static/njs/fancy_index.njs:13)
 while sending response to client, client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/before.html", host: "10.1.10.111"
2023/10/06 09:18:01 [error] 98853#98853: *5 open() "/data/mirrors/fancy-index/after-legacy" failed (2: No such file or directory), client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/after-legacy", host: "10.1.10.111"
2023/10/06 09:18:01 [error] 98853#98853: *5 js exception: TypeError: cannot get property "match" of undefined
    at anonymous (/usr/share/nginx/site/static/njs/markup.min.njs:6)
    at anonymous (/usr/share/nginx/site/static/njs/fancy_index.njs:13)
 while sending response to client, client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/before-legacy.html", host: "10.1.10.111"
2023/10/06 09:22:51 [error] 98858#98858: *6 open() "/data/mirrors/fancy-index/after-legacy" failed (2: No such file or directory), client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/after-legacy", host: "10.1.10.111"
2023/10/06 09:22:51 [error] 98858#98858: *6 js exception: TypeError: cannot get property "match" of undefined
    at anonymous (/usr/share/nginx/site/static/njs/markup.min.njs:6)
    at anonymous (/usr/share/nginx/site/static/njs/fancy_index.njs:13)
 while sending response to client, client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/before.html", host: "10.1.10.111"
2023/10/06 09:22:51 [error] 98858#98858: *7 open() "/data/mirrors/fancy-index/after-legacy" failed (2: No such file or directory), client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/after-legacy", host: "10.1.10.111"
2023/10/06 09:22:51 [error] 98858#98858: *7 js exception: TypeError: cannot get property "match" of undefined
    at anonymous (/usr/share/nginx/site/static/njs/markup.min.njs:6)
    at anonymous (/usr/share/nginx/site/static/njs/fancy_index.njs:13)
 while sending response to client, client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/before.html", host: "10.1.10.111"
2023/10/06 09:22:51 [error] 98857#98857: *8 open() "/data/mirrors/fancy-index/after-legacy" failed (2: No such file or directory), client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/after-legacy", host: "10.1.10.111"
2023/10/06 09:22:51 [error] 98857#98857: *8 js exception: TypeError: cannot get property "match" of undefined
    at anonymous (/usr/share/nginx/site/static/njs/markup.min.njs:6)
    at anonymous (/usr/share/nginx/site/static/njs/fancy_index.njs:13)
 while sending response to client, client: 10.1.10.250, server: _, request: "GET /blender/ HTTP/1.1", subrequest: "/fancy-index/before.html", host: "10.1.10.111"

排查了一下,应该和 njs 0.8 之后 API 的变化有关。请帮忙测试以下补丁是否能工作

diff --git a/static/njs/fancy_index.njs b/static/njs/fancy_index.njs
index 17cc091..3b06615 100644
--- a/static/njs/fancy_index.njs
+++ b/static/njs/fancy_index.njs
@@ -9,7 +9,7 @@ function fancyIndexRender(r, templateUrl){
     if(rTmpl.status != 200){
       return r.return(rTmpl.status);
     }
-    var tmpl = rTmpl.responseBody;
+    var tmpl = rTmpl.responseText;
     var result = Mark.up(tmpl, {
       url: r.variables.request_uri.replace(/\/+/g, '/').replace(/\?.*$/, ''),
       open: '{{',
diff --git a/static/njs/legacy_index.njs b/static/njs/legacy_index.njs
index 681f698..396ced3 100644
--- a/static/njs/legacy_index.njs
+++ b/static/njs/legacy_index.njs
@@ -24,7 +24,7 @@ function legacyIndexRender(r){
     if(rTmpl.status != 200){
       return r.return(rTmpl.status);
     }
-    var tmpl = rTmpl.responseBody;
+    var tmpl = rTmpl.responseText;
     
     r.subrequest('/static/njs/options.json', {
       args: '',
@@ -36,7 +36,7 @@ function legacyIndexRender(r){
       }
       var global_options;
       try{
-        global_options = JSON.parse(rOpt.responseBody);
+        global_options = JSON.parse(rOpt.responseText);
       }catch(e){
         return r.return(500);
       }
@@ -58,7 +58,7 @@ function legacyIndexRender(r){
         var mirs = unlisted;
         if(rMirs.status == 200){
           try{
-            mirs = mirs.concat(JSON.parse(rMirs.responseBody));
+            mirs = mirs.concat(JSON.parse(rMirs.responseText));
           }catch(e){
           }
         }

问题已解决,感谢
image