Serving requests to always-on python application from Apache - python

I’ve been running an Apache + PHP webserver for years with no issues. I would like to add a python application to the server, but I can’t figure out how to connect Apache to a python application that is always running. In short, I don’t know the name of the concept or buzzword to research regarding using Apache to send requests back and forth to a python script that is listening on a specific port.
The python script is part of the Microsoft Teams bot framework. It typically runs on port 3978, which means I need Apache to listen for requests to https://bot.example.com and then communicate the requests to localhost:3978. The python application needs to always be running to perform proactive tasks, such as messaging reminders to users, but that’s not important.
The main idea is to use Apache for ssl, presumably because it is battle tested, as the front end while a python application runs in a forever loop to handle the requests. I have searched for hours, but I can’t figure out how to get started even though I am experienced with both Apache and python. Any help would be greatly appreciated.

Related

Can I run WSGI server with gunicorn without python web frameworks in a resource-constrained environment?

I know it's a bit absurd to ask, but can I avoid using web frameworks like - Flask, Falcon, etc and run bare-minimal WSGI server in an nginx environment. I am trying to run my WSGI process in a tight and highly-resource-constrained environment - something like Raspberry Pi. I will not be requiring to handle much of the client load. The number of clients will be 1 or 2 at max. No more than 10 queries per second. So just wondering if I can knock out every component possible by writing some Python code myself.
I have been searching for any documentation on this, but couldn't get much info. Any pointers or suggestions to serve custom python web application without a full-fledged framework is welcome. Last resort would be to understand falcon source code and write a minimal API code myself, which I have already started.

How to run rqworker for python-rq

I have a small Python flask webserver on an Ubuntu box (ngnix and uwsgi) that I just started using to receive and process webhooks. Part of the webhook processing can include sending an email, which I noticed causes a delay and subsequently blocks the response back to the server sending the webhook.
In researching a way to mitigate this, I discovered python-rq (aka rq), which lets me queue up a function call and then immediately respond to the webhook. In testing, this works great!
I'm testing it on my server, and to start rq I have to run rqworker in the same directory as my website. This is great for testing, but I don't want to have to log into the server to start rq just to keep in running.
Some ideas I've come across:
The python-rq docs mention supervisor, http://python-rq.org/patterns/supervisor/, but I don't know if I need that much overhead.
Would a simple cron job do the trick, using reboot?
This is a small internal-only server. I don't want to over-engineer it (I feel like I'm creeping in that direction already), but I also don't want to have to babysit it to make sure all of the pieces are working.
How can I set up rqworker to run in the web site application directory on its own?

How do I get a CGI script to run under on a Tornado web server?

I'm trying out several web servers. Today I'm trying out the Tornado web server.
One of the first things I do when I try out a new web server is get the web server to run my test CGI script.
I see a bunch of information at http://www.tornadoweb.org/en/stable/wsgi.html about how to get the Tornado web server to run scripts that use the WSGI protocol (it involves WSGIContainer).
But I don't see anything at the tornadoweb.org site about how to get the Tornado web server to run scripts that use the CGI protocol. (Am I overlooking something? Is there maybe somewhere else that talks about getting a Tornado web server to execute CGI scripts?)
I'm mystified, because literally every other web server I've ever tried out has some way to run CGI scripts using the standard CGI protocol.
My Tornado web server is simply serving up the my CGI script file as text on my web browser screen; as far as I can tell it never executes the CGI script.
(Perhaps I've missed some essential configuration step?)
Am I missing some documentation that tells how to persuade Tornado to execute the CGI script, rather than copy it to the web browser? Please link to it.
Do maybe people who run the Tornado web server always run some other web server to handle CGI scripts? Please link to something that shows how I can get Tornado and some other web server to run more-or-less simultaneously on the same machine and split up their duties.
(This is not a duplicate of the "
Tornado or Django works with CGI?
" question
which asks how to get tornado to run as a CGI script under some other web server application. In my case, tornado is the only web server application on this machine, and I'm trying to get some simple CGI script to run under Tornado).
Tornado does not support CGI. Tornado is not a general-purpose web server in the way that Apache and nginx are; it is designed to run applications built with the Tornado framework (i.e. tornado.web.RequestHandler and friends). There is some interoperability with other frameworks via the WSGI module, and it would be possible to implement CGI on top of Tornado's HTTPServer, it's kind of missing the point.
Many Tornado users run nginx as a proxy in front of a Tornado server, and nginx can also run CGI, so this would be a good way to incorporate CGI into your setup if you need it.

socket.io like for Python 2.7 + Bottle framework

I am developing my web app with Python 2.7 + Bottle. Everything is great and python is an amazing language coming from ASP.NET. I am building a web application that needs to use real-time client/server communication and socket.io for node.js comes to mind.
I wanted to know how can I implement socket.io-like using Python + bottle. I've read this article on bottle, but I can't still seem to understand how it works - what I need to install, and how all works out (code examples?).
I really need that for my next web application but need help in understanding what I need to put in my project in order for it to work. I have no problem working with 'preview' codes which aren't stable release yet. I'm developing on Windows platform. Thanks.
I also want to know if its scalabe. whether I can use redis in the back so all calls will be sync when running my website on several servers, so when one client send data, all the other clients connected to the other servers will get it to.
maybe websocket can help you,many modern browser support this protocol,but bottle.py don't support it now,you can get some idea from tornado.websocket and some answer here
cause every connection can be saved,so i guess it can run on several servers,but i never implement.
since bottle is micro framework,you should do something by yourself.

Can I run Bottle.py on my Apache server without disrupting my PHP apps?

I'm antsy to get Python running on my webserver after just recently picking it up.
I chose Bottle.py because it looks simple, accessible, and contained. I have very little experience with or knowledge of how exactly webservers work (how to mess with them) and I'm reluctant to play with my server's Apache if I don't need to since it hosts a very active message board already.
Bottle's documentation seemed to assume a step or two of server/python understanding that I don't have, as I'm not even sure where to put the actual routes/website content once I already have bottle.py copied over to my doc root. Or how the server knows to run bottle (or execute python) when I go to "mydomain.com".
Run it in a WSGI container such as mod_wsgi.
You can also run Apace as a proxy to your application. I believe using mod_proxy would get you there. I myself run a nginx front end as reverse proxy to a bottle application running on bjoern. Bjoern itself is quite capable of running the bottle app, so I didn't want to use mod_wsgi, and similar stuff.

Categories