On 2022/12/18 10:23:39 +0000, indivC <ind...@proton.me> wrote:
> On Sunday, December 18th, 2022 at 9:04 AM, Omar Polo <o...@omarpolo.com> 
> wrote:
> > Since httpd speaks fastcgi, why not write some python code that
> > accepts the requests over fastcgi? (assuming this is what you're
> > trying to do, but you didn't tell.)
> 
> I believe that is exactly what I'm trying to do. 
> The end goal is to be able access a python(1) file from httpd(8).
> My understanding is you have to configure slowcgi(8),
> which utilizes fastcgi, within httpd(8).
> I've been able to configure that without any problems using perl(1),
> but not with python(1).

not exactly, fastcgi is a binary protocol, whereas from what you're
writing I'm assuming you're trying to run a CGI script written in
python with slowcgi.

(this is what I meant with "explain what you're trying to do" as there
is a big difference between running a python web application and
running a custom CGI script.)

there are less ugly hacks (IMHO) than one can do with slowcgi instead
of installing huge things like scripting languages inside the /var/www
chroot, but...

> With python(1), because the problem is occurring
> before I even get to httpd(8), I left that out of the message. 
> If I attempt to access the python(1) file currently, 
> I still see the same 'ld.so' error message I mentioned before.
> Therefore, I was trying to leave out httpd(8)
> and slowcgi(8) configuration as that isn't where the problem lies. 
> 
> As mentioned before, if you have a better solution for this, 
> please share.
> Any links you can provide for step by step instructions 
> or general steps on how to accomplish this would be helpful. 
> 
> Thanks.

...I think that instead of installing python in the /var/www chroot
(plus all the dependencies you'd need) if you really want to use httpd
and write your stuff in python you may have your python script talk
fastcgi instead.

On pypi there is a 'fastcgi' library.  it's not packaged on OpenBSD
and I can't asses how good it is, I'm not reccomanding it (just did a
random search on the web and was the first result), but at least seems
to work: (modeled after the example code in the github repo)

    #!/usr/bin/env python
    # hello.py
    
    from fastcgi import *
    from socketserver import TCPServer
    
    class MyHandler(FcgiHandler):
        def handle(self):
            self.print('Content-type: text/plain\n')
            self.print("Hello, world!")
    
    addr = ('localhost', 8888)
    with TCPServer(addr, MyHandler) as srv:
        srv.serve_forever()

and here's the matching httpd.conf bit

    server "localhost" {
        listen on * port 80
        fastcgi socket tcp localhost 8888
    }

this has the advantage of not needing to fork one process per request
like CGI would do, but you need to secure your application by yourself
(running it as a different user for starters -- no idea if you can do
fancier things with python.)

Reply via email to