Is there any possible way to use mod_wsgi on localhost? - apache

I am a beginner of mod_wsgi. I just want to develop basic handler application to Apache. Here is my simple test.wsgi code. Apache localhost calls this wsgi first.
def application(environ,start_response):
if (environ["PATH_INFO"]=="/"):
start_response('200 OK', [])
return ['It works']
else:
path = environ["SERVER_NAME"] + environ["PATH_INFO"]
start_response("303 See Other", [('location', path)])
return [path]
But the main problem is localhost redirects too many times. Please help me to solve this problem? Is there any possible way? I want to develop simple handler application which analyzes environ[query_string].
Many thanks,
Zoloo

Read:
http://www.python.org/dev/peps/pep-0333/#url-reconstruction
for the correct way to go about reconstructing the URL for use in redirects etc.
Better still, go use a micro framework like Flask. If you are new to this stuff trying to use WSGI at its most basic level is a bad idea. Use a system which does all this stuff for you properly.

Related

how to properly see the errors of a flask application in production mode

I have made a flask application at my local computer in the debugging mode and it runs all fine. But when it comes to production, the website gives me 500 or internal server error, which I have no idea what the bug is. I am fairly new to flask production and this has been stopping me from moving forward for quite a few days.
My questions are:
1> in my local development environment, one could always print things out. But how can I see those prints in the production stage?
2> Do I see them through Apache2 log? Where is Apache2 log?
For production, I actually followed the tutorials from pythonprogramming.net. Youtube link is here:
https://www.youtube.com/watch?v=qZNL4Ku1UQg&list=PLQVvvaa0QuDc_owjTbIY4rbgXOFkUYOUB&index=2
To use a very simple example, if the code imports a package which wasn't installed, where can we see the errors?
Thanks in advance.
I've tried to use to use try ... except block for every flask function. Whenever there is an exception, it can be return to the front-end. But what about other errors?
I found out:
Use logging module
Read apache2 log from /var/log/apache2

Can't disable WSGIErrorOverride

I am backing a web app with a Flask API that returns custom error codes. The API runs through Apache and the WSGI module, in daemon mode.
I included a WSGIErrorOverride Off instruction in the Apache conf file for the API (which is supposed to be the default but I included it anyway).
Yet anytime my Flask app returns a custom error code (they work when I run the app using the built-in server), Apache sends an error 500. How can I prevent that?
Thanks to comments by duskwuff and Graham Dumpleton, I found that the problem doesn't come from Apache WSGI but from my Flask app.
More precisely, I was using the Flask-RESTful package, which is in charge, among other things, of transforming my views' return values into actual responses.
When those views are decorated (here with an equivalent of #login_required), those decorators are called by the Flask-RESTful package itself, and when an exception is thrown, something goes wrong.
For some reason, my app returns the custom error when I run the built-in server and an error 500 when I run it over Apache. Not quite sure why yet, I'm guessing Flask-RESTful is doing something that is not WSGI-compliant. I was on the verge of dropping it anyway for other reasons, so I'm OK with this solution.
Update: it looks like the problem does indeed come from Flask-RESTful: https://github.com/flask-restful/flask-restful/issues/372

Proxy settings in RStudio for third party API access

I'm using RStudio on a server that is behind my company's firewall. I referred to the link here and did the same changes in my RProfile script:
RProfile
http_proxy=http://proxy.dom.com:80
http_proxy_user=user:passwd
I'm trying to access an API (Omniture a.k.a. api.omniture.com) using the package RSiteCatalyst and even though I mentioned the proxy, I'm unable to bypass the firewall. Below is what I do:
library(RSiteCatalyst)
SCAuth('username','shared-secret') # Authentication
And the error that I get
Error in function (type, msg, asError = TRUE) :
Could not resolve host: api.omniture.com
Before going to IT I came here for the StackOverflow gods to help out. Would greatly appreciate it. Thanks.
I think that article has a typo. Can you put the http_proxy lines in your .Renviron rather than your .Rprofile, then restart RStudio? (If that does the job, we'll update the article!)

FastCGI authorizer support in lighttpd broken?

I'm in the process of writing a webapp in C++ using FastCGI with lighttpd. The reason I'm doing this the painful way is because the end product will go on an embedded device. Originally, I didn't know about FCGI modes; I thought everything was basically a responder. Then I learned about authorizers, and I've been trying to enable support for it.
Lighttpd seems to have no trouble putting an authorizer in front of static content, but when I try to protect another FCGI script it gives me 403 forbidden.
I've done a lot of research, and come to some conclusions:
Lighttpd's support for the "Variable-VAR_NAME: value" passing from authorizer to subsequent FCGIs is broken.
The language in the first link implies that you can protect dynamic content with authorizers, but this bug report says otherwise.
For the record, I'm using lighttpd 1.4.28 (x86 and ARM) and custom authentication (password hashed on client with SHA-512), because (1) TLS is impossible/unnecessary for this application, (2) basic HTTP authentication is not good enough, (3) digest authentication is broken in lighttpd, and (4) this isn't really intended to be a secure system anyway.
Here's the relevant part of my lighttpd.conf file:
fastcgi.server = (
"main.fcgi" =>
(( "mode" => "responder",
"bin-path" => "/var/fcgi/main.fcgi",
"socket" => "/tmp/fcgi.sock",
"check-local" => "disable",
"max-procs" => 1
)),
"/" =>
(( "mode" => "authorizer",
"bin-path" => "/var/fcgi/auth.fcgi",
"socket" => "/tmp/fcgi.sock",
"check-local" => "disable",
"max-procs" => 1,
"docroot" => "/var/fcgi"
))
)
To wrap it up, can anyone give me guidance on using an FCGI authorizer to control access to other FCGI scripts(/binaries), instead of just static files, on lighttpd? It would also be nice to get variable-passing working. Thanks for reading this far!
Everything I've seen seems to indicate that FastCGI authorizers do not work accroding to spec in lighttpd. What I've done is implemented my own authorization scheme inside my normal responder code. This is fine for my purposes, but more complex websites may really feel the pain from this one. :( If anyone comes up with a better answer for this, respond and I'll eventually get around to changing the answer to yours.
Update: lighttpd fixed this in lighttpd 1.4.42, released back in 2016.
https://redmine.lighttpd.net/issues/321

Is this ok to use COM in Apache module

I need to write a module for Apache. The server will be running under Windows and it looks that I will need to utilize some functionality which is implemented as COM.
Is this ok to use COM in Apache module or should I try to avoid this?
There is no inherent reason to avoid this. I recommend that you completely disconnect from the COM object at the end of the request, and uninitialize COM, in the first version. Once you have that working, you can start trying to preserve some state across calls - just remember that Apache's process and threading model may result in state not being preserve across requests.