Welcome! Log In Create A New Profile

Advanced

Re: serving files from /proc

J Carter
December 12, 2023 10:20PM
On Wed, 13 Dec 2023 02:45:54 +0000
J Carter <jordanc.carter@outlook.com> wrote:

> Hello,
>
> On Tue, 12 Dec 2023 16:17:11 +0100
> Jérôme Loyet <ml@fatbsd.com> 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.
>
> <Example of how IO with njs can be done here>
> 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.

> <as seen here>
> 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
Subject Author Posted

serving files from /proc

Jérôme Loyet December 12, 2023 10:18AM

Re: serving files from /proc

Francis Daly December 12, 2023 12:44PM

Re: serving files from /proc

J Carter December 12, 2023 09:48PM

Re: serving files from /proc

J Carter December 12, 2023 10:20PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 302
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready