• Spawning nginx instance on demand

    From Andre Rodier@3:633/10 to All on Sunday, May 31, 2026 19:40:02
    Hello,
    I have an Nginx server running on Debian Trixie, as a "user" systemd
    service. It is working, but if I have 100 users, I don't want to spawn
    100 nginx servers just for waiting for connections.
    Each nginx instance "listen" on a unix socket in /run/user directory.
    I tried sockets triggering, and while the log is working, triggering
    the nginx server fails, because the socket is already opened.
    Is there a better way to achieve this, i.e. spawning nginx instance on
    demand ?
    Thanks.
    --
    ? https://rodier.me/


    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Nicolas George@3:633/10 to All on Sunday, May 31, 2026 19:50:02
    Andre Rodier (HE12026-05-31):
    Hello,

    I have an Nginx server running on Debian Trixie, as a "user" systemd
    service. It is working, but if I have 100 users, I don't want to spawn
    100 nginx servers just for waiting for connections.

    Each nginx instance "listen" on a unix socket in /run/user directory.

    I tried sockets triggering, and while the log is working, triggering
    the nginx server fails, because the socket is already opened.

    Is there a better way to achieve this, i.e. spawning nginx instance on
    demand ?

    First hit on a web search about ?nginx systemd socket activation?:

    https://www.freedesktop.org/wiki/Software/systemd/DaemonSocketActivation/

    Not tested it.

    But if you need to start 100 instances of nginx and are looking how to
    achieve it, you probably have an XY problem where you mistakenly assumed
    you need 100 instances of nginx to achieve your real goal. But you have
    not share your real goal.

    Regards,

    --
    Nicolas George

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andre Rodier@3:633/10 to All on Sunday, May 31, 2026 20:20:01
    On Sun May 31, 2026 at 6:42 PM BST, Nicolas George wrote:
    Andre Rodier (HE12026-05-31):
    Hello,

    I have an Nginx server running on Debian Trixie, as a "user" systemd
    service. It is working, but if I have 100 users, I don't want to spawn
    100 nginx servers just for waiting for connections.

    Each nginx instance "listen" on a unix socket in /run/user directory.

    I tried sockets triggering, and while the log is working, triggering
    the nginx server fails, because the socket is already opened.

    Is there a better way to achieve this, i.e. spawning nginx instance on
    demand ?

    First hit on a web search about ?nginx systemd socket activation?:

    https://www.freedesktop.org/wiki/Software/systemd/DaemonSocketActivation/

    Not tested it.

    But if you need to start 100 instances of nginx and are looking how to achieve it, you probably have an XY problem where you mistakenly assumed
    you need 100 instances of nginx to achieve your real goal. But you have
    not share your real goal.

    Regards,
    First hit on a web search about ?nginx systemd socket activation?:
    Yes, I can use a search engine too, found the same kind of results, and they're not really helpful.
    I can detail more what I have so far, then.
    - I have one nginx instance, running as a system systemd service, usng basic authentication (on pam).
    - I have nginx user instances for each user (used as webdav servers)
    - The system server uses proxy_pass directive to dispatch queries to each user?s nginx instance.
    In the system instnace, the dispatch works with this block:
    ~~~
    proxy_pass http://unix:/var/tmp/webdav-user/$remote_user/socket;
    root /home/$remote_user/webdav/root;
    autoindex on;
    ~~~
    Everything works as expected. However, if I had 100 users (that's just an example), I would like to avoid having 100 nginx instances waiting.
    I would like to spawn the user?s instance on demand, not having them waiting for nothing.
    I tested the socket activation, and the systemd logic is working, i.e. it is calling the user systemd service.
    BUT, the user service fails to start, because the socket is own by systemd.

    I hope it is clear for everyone.
    Thanks
    --
    ? https//rodier.me/


    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Dan Ritter@3:633/10 to All on Monday, June 01, 2026 00:10:01
    Andre Rodier wrote:
    On Sun May 31, 2026 at 6:42 PM BST, Nicolas George wrote:

    But if you need to start 100 instances of nginx and are looking how to achieve it, you probably have an XY problem where you mistakenly assumed you need 100 instances of nginx to achieve your real goal. But you have
    not share your real goal.

    - I have one nginx instance, running as a system systemd service, usng basic authentication (on pam).
    - I have nginx user instances for each user (used as webdav servers)


    ~~~
    proxy_pass http://unix:/var/tmp/webdav-user/$remote_user/socket;
    root /home/$remote_user/webdav/root;
    autoindex on;
    ~~~

    Why don't you just have a single system nginx run all these via
    a location or such?

    -dsr-

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andy Smith@3:633/10 to All on Monday, June 01, 2026 01:00:01
    Hi,

    On Sun, May 31, 2026 at 07:09:38PM +0100, Andre Rodier wrote:
    I tested the socket activation, and the systemd logic is working, i.e.
    it is calling the user systemd service. BUT, the user service fails to
    start, because the socket is own by systemd.

    I have not tried to do what you're doing, but I note that .socket units
    can have the options:

    SocketUser
    SocketGroup
    SocketMode

    so can these be used to create the socket with ownership of user and
    read/write to system nginx?

    I am not sure about the idea of running one nginx process per active
    user, about wehther that would be scalable, but I guess it is still more scalabvle than running a container or a VM per user.

    Thanks,
    Andy

    --
    https://bitfolk.com/ -- No-nonsense VPS hosting

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Nicolas George@3:633/10 to All on Monday, June 01, 2026 10:40:01
    Andre Rodier (HE12026-05-31):
    Yes, I can use a search engine too, found the same kind of results, and they're not really helpful.

    At this point, what is not really helpful is you saying the results are
    not really helpful.

    What you should be saying instead is (1) what search result you used,
    (2) what you tried exactly and (3) hot it failed.

    I can detail more what I have so far, then.

    - I have one nginx instance, running as a system systemd service, usng basic authentication (on pam).
    - I have nginx user instances for each user (used as webdav servers)
    - The system server uses proxy_pass directive to dispatch queries to each user?s nginx instance.

    To prove you are not having a XY problem, you need to explain why you
    think an instance of nginx per user is preferable to the built-in
    mechanism it offers for dav.

    I tested the socket activation, and the systemd logic is working, i.e. it is calling the user systemd service.
    BUT, the user service fails to start, because the socket is own by systemd.

    As said above, you need to show exactly what you did and how it failed.

    Regards,

    --
    Nicolas George

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Nicolas George@3:633/10 to All on Monday, June 01, 2026 10:40:01
    Andy Smith (HE12026-05-31):
    so can these be used to create the socket with ownership of user and read/write to system nginx?

    Maybe let us ask for the error message before randomly assuming the
    issue is caused by permissions.

    (My guess is the issue is not caused by permissions.)

    Regards,

    --
    Nicolas George

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andre Rodier@3:633/10 to All on Monday, June 01, 2026 11:00:01
    On Mon Jun 1, 2026 at 9:32 AM BST, Nicolas George wrote:
    Andy Smith (HE12026-05-31):
    so can these be used to create the socket with ownership of user and
    read/write to system nginx?

    Maybe let us ask for the error message before randomly assuming the
    issue is caused by permissions.

    (My guess is the issue is not caused by permissions.)

    Regards,
    Yes, it is not permissions. Here is the exact error message:
    ~~~
    bind() to unix:/run/user/1001/nginx-webdav.socket failed (98: Address already in use)
    ~~~
    I think this behaviour is normal, as the socket is already created by systemd socket file.
    My question would be something like ?is there a way to share the socket between systemd and nginx? ?
    Since systemd let me run a service when a socket is accessed, I thought that there would be an nginx option to listen on an already existing socket.
    --
    ? https//rodier.me/


    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andre Rodier@3:633/10 to All on Monday, June 01, 2026 11:10:02
    On Mon Jun 1, 2026 at 9:30 AM BST, Nicolas George wrote:
    Andre Rodier (HE12026-05-31):
    Yes, I can use a search engine too, found the same kind of results, and they're not really helpful.

    At this point, what is not really helpful is you saying the results are
    not really helpful.

    What you should be saying instead is (1) what search result you used,
    (2) what you tried exactly and (3) hot it failed.

    I can detail more what I have so far, then.

    - I have one nginx instance, running as a system systemd service, usng basic authentication (on pam).
    - I have nginx user instances for each user (used as webdav servers)
    - The system server uses proxy_pass directive to dispatch queries to each user?s nginx instance.

    To prove you are not having a XY problem, you need to explain why you
    think an instance of nginx per user is preferable to the built-in
    mechanism it offers for dav.
    I am using the built-in dav mechanism, I don't think I ever wrote I am using a custom one.
    Running as a user has the advantage of simplifying the permissions management, files are read and written with the right user account.
    The overall mechanism works perfectly, I want to optimise if possible.

    I tested the socket activation, and the systemd logic is working, i.e. it is calling the user systemd service.
    BUT, the user service fails to start, because the socket is own by systemd.

    As said above, you need to show exactly what you did and how it failed.
    Answered in the other thread

    Regards,
    Same,
    --
    ? https//rodier.me/


    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Nicolas George@3:633/10 to All on Monday, June 01, 2026 11:20:01
    Andre Rodier (HE12026-06-01):
    ~~~
    bind() to unix:/run/user/1001/nginx-webdav.socket failed (98: Address already in use)
    ~~~

    I think this behaviour is normal, as the socket is already created by systemd socket file.
    My question would be something like ?is there a way to share the socket between systemd and nginx? ?

    The answer is in the web page I linked in my first reply.

    Regards,

    --
    Nicolas George

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)