serving files from /proc
Hello, I'm trying to serve some files from /proc but nginx return a 0 bytes content because the file size of many files in /proc/ tree is simply 0 by design. here is my sample conf file: ... location = /route { root /proc/net; } and the result of the corresponding curl: > GET /route HTTP/1.1 > Host: 172.16.0.3:1513 > User-Agent: curl/7.68.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Server: nginx/1.23.1 < Date: Tue, 12 Dec 2023 15:08:00 GMT < Content-Type: text/plain < Content-Length: 0 < Last-Modified: Tue, 12 Dec 2023 15:08:00 GMT < Connection: keep-alive < ETag: "65787750-0" < Accept-Ranges: bytes is there a simple way to configure nginx to return the cotent of /proc/net/route or any other file in /proc ? thanks regards ++ Jerome ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: serving files from /proc
On Tue, Dec 12, 2023 at 04:17:11PM +0100, Jérôme Loyet wrote: Hi there, > I'm trying to serve some files from /proc but nginx return a 0 bytes > content because the file size of many files in /proc/ tree is simply 0 by > design. I suspect that you are going to have to write something to read the file and tell nginx what the "real" size and content is. Stock nginx knows that for static files, when the filesystem says that st_size is 0, the file has a size of 0. That happens to not be true for some things within /proc; so either you get to change the code behind /proc to return "real" values, or you get to write something to return real values. I guess it will be simpler to run something like a fastcgi process that will "cat" the file, and tell nginx to fastcgi_pass to that process for these requests; than to rewrite the /proc code or to rewrite the nginx static file handler to do extra things when it is told that the size is 0. > is there a simple way to configure nginx to return the cotent of > /proc/net/route or any other file in /proc ? Untested, but I suspect "directly: no; indirectly, maybe (as above)". Cheers, f -- Francis Dalyfran...@daoine.org ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: serving files from /proc
Hello, On Tue, 12 Dec 2023 16:17:11 +0100 Jérôme Loyet wrote: > Hello, > > I'm trying to serve some files from /proc but nginx return a 0 bytes > content because the file size of many files in /proc/ tree is simply 0 by > design. That is correct, reading Virtual File System files would require special handling compared to regular files. Nginx doesn't appear to have this. > > here is my sample conf file: > ... > location = /route { > root /proc/net; > } > > and the result of the corresponding curl: > > GET /route HTTP/1.1 > > Host: 172.16.0.3:1513 > > User-Agent: curl/7.68.0 > > Accept: */* > > > * Mark bundle as not supporting multiuse > < HTTP/1.1 200 OK > < Server: nginx/1.23.1 > < Date: Tue, 12 Dec 2023 15:08:00 GMT > < Content-Type: text/plain > < Content-Length: 0 > < Last-Modified: Tue, 12 Dec 2023 15:08:00 GMT > < Connection: keep-alive > < ETag: "65787750-0" > < Accept-Ranges: bytes > > is there a simple way to configure nginx to return the cotent of > /proc/net/route or any other file in /proc ? For a solution entirely within nginx, you can use njs to serve /proc/net/route. https://github.com/nginx/njs-examples?tab=readme-ov-file#file-io-misc-file-io Njs does handle VFS/zero sized files in a special way. If the file is zero sized, it will read up to 4096 bytes from the file. https://github.com/nginx/njs/blob/2c937050a4589bbc196db334fef22e6de772dd49/external/njs_fs_module.c#L2732 > thanks > regards > ++ Jerome ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: serving files from /proc
On Wed, 13 Dec 2023 02:45:54 + J Carter wrote: > Hello, > > On Tue, 12 Dec 2023 16:17:11 +0100 > Jérôme Loyet wrote: > > > Hello, > > > > I'm trying to serve some files from /proc but nginx return a 0 bytes > > content because the file size of many files in /proc/ tree is simply 0 by > > design. > > That is correct, reading Virtual File System files would require special > handling compared to regular files. Nginx doesn't appear to have this. > > > > > here is my sample conf file: > > ... > > location = /route { > > root /proc/net; > > } > > > > and the result of the corresponding curl: > > > GET /route HTTP/1.1 > > > Host: 172.16.0.3:1513 > > > User-Agent: curl/7.68.0 > > > Accept: */* > > > > > * Mark bundle as not supporting multiuse > > < HTTP/1.1 200 OK > > < Server: nginx/1.23.1 > > < Date: Tue, 12 Dec 2023 15:08:00 GMT > > < Content-Type: text/plain > > < Content-Length: 0 > > < Last-Modified: Tue, 12 Dec 2023 15:08:00 GMT > > < Connection: keep-alive > > < ETag: "65787750-0" > > < Accept-Ranges: bytes > > > > is there a simple way to configure nginx to return the cotent of > > /proc/net/route or any other file in /proc ? > > For a solution entirely within nginx, you can use njs to serve > /proc/net/route. > > > https://github.com/nginx/njs-examples?tab=readme-ov-file#file-io-misc-file-io > > Njs does handle VFS/zero sized files in a special way. If the file is zero > sized, it will read up to 4096 bytes from the file. > *Correction - it read up until EOF. So any sized VFS file will work actually even above 4096 bytes. > > https://github.com/nginx/njs/blob/2c937050a4589bbc196db334fef22e6de772dd49/external/njs_fs_module.c#L2732 > > > > thanks > > regards > > ++ Jerome > ___ > nginx mailing list > nginx@nginx.org > https://mailman.nginx.org/mailman/listinfo/nginx ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx