Running mod-wsgi code (.wsgi) with Apache2 - apache

I'm using mod_wsgi on apache2/Mac OS X by setting apache server as follows.
<Directory /Library/WebServer/Documents/wsgi/scripts>
Order allow,deny
Allow from all
</Directory>
<IfModule wsgi_module>
WSGIScriptAlias /test /Library/WebServer/Documents/wsgi/scripts/test.wsgi
</IfModule>
With this configuration, I could call test.wsgi with http://.../test
Now, I need to execute it by calling as follows.
http://.../wsgi/test.wsgi
I have the following code.
<Directory /Library/WebServer/Documents/wsgi/scripts>
Order allow,deny
Allow from all
AddHandler wsgi-script .wsgi
</Directory>
<IfModule wsgi_module>
WSGIScriptAlias /test /Library/WebServer/Documents/wsgi/scripts/test.wsgi
Alias /wsgi/ /Library/WebServer/Documents/wsgi/scripts/
</IfModule>
I thought about using Alias so that I could link wsgi script directory to /wsgi/, and I expect Addhandler can handle the wsgi file, but it doesn't work.
What's wrong with my apache2 setup?
SOLVED
<Directory /Library/WebServer/Documents/wsgi/scripts>
Options ExecCGI Indexes
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
Order allow,deny
Allow from all
</Directory>
Alias /wsgi/ /Library/WebServer/Documents/wsgi/scripts/

Don't use AddHandler with WSGIScriptAlias, you need to use AddHandler with Alias directive. You will need to set ExecCGI option as well for directory. See:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines

Related

Acache: wsgi and alias incompatibility

I am trying to setup Apache so that:
if the user goes to /temp then the file /home/temp/public_html/index.html is served
if the user goes to /temp/app then my mod-wsgi /home/temp/app/start.wsgi is executed
I currently have this:
<VirtualHost *:80>
WSGIDaemonProcess temp user=temp group=temp home=/home/temp/app
WSGIScriptAlias /temp/app /home/temp/app/start.wsgi
Alias /temp /home/temp/public_html
<Directory /home/temp/app>
WSGIProcessGroup temp
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost *:80>
But oddly enough Alias seems to take predence over WSGIScriptAlias and /temp/app does not work...
You got closer in your own answer, but not quite. Use something like:
<VirtualHost *:80>
WSGIDaemonProcess temp user=temp group=temp home=/home/temp/app
Alias /temp/app /home/temp/app/start.wsgi
Alias /temp /home/temp/public_html
<Directory /home/temp/app>
WSGIProcessGroup temp
WSGIApplicationGroup %{GLOBAL}
Require all granted
Options ExecCGI
AddHandler wsgi-script .wsgi
</Directory>
</VirtualHost>
Not particularly pretty, but I have (at least for the time being) solved it this way:
<VirtualHost *:80>
WSGIDaemonProcess temp user=temp group=temp home=/home/temp/app
<Directory /home/temp/app>
WSGIProcessGroup temp
WSGIApplicationGroup %{GLOBAL}
Options ExecCGI MultiViews
MultiviewsMatch Handlers
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
Require all granted
</Directory>
Alias /temp /home/temp/app
</VirtualHost>
Instead of using WSGIScriptAlias, I define it to automatically run .wsgi files. The MultiViews option matches file to file.wsgi.
Furthermore, to hide the extension from my own script, in each .wsgi I have to redefine the script filename:
from server_public import app as _application # my flask app
# get rid of the .wsgi extension
def application(environ, start_response):
if environ['SCRIPT_NAME'].endswith('.wsgi'):
environ['SCRIPT_NAME'] = environ['SCRIPT_NAME'][:-5]
return _application(environ, start_response)
I also had to move my public_html/index.html to app/index.html.
I would prefer a simpler solutions where I served index.html for /temp, and a script alias for /temp/app... But not sure that is possible...

Apache php httpd-xampp.conf alias not working

I have httpd-xampp.conf with
<IfModule alias_module>
...
Alias /examples "D:/xampp/htdocs/examples/"
<Directory "D:/xampp/htdocs/examples">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</IfModule>
an in examples folder i have index.html, but when i access http://localhost:8880/examples, i have error
This page was not found
You are not logged in.
Back Log in Issues
Is there any error of my config? other alias : phpmyadmin, security work well.
I change httpd-xampp.conf to
<IfModule alias_module>
...
#!!! Don't know why
#Alias /examples "D:/xampp/examples/" don't work
Alias /my-examples "D:/xampp/examples/"
<Directory "D:/xampp/examples">
AllowOverride AuthConfig
Require all granted
</Directory>
</IfModule>
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info|my-examples))">
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
and http://localhost:8880/my-examples work now

Configuring apache with fastcgi in Haskell

I am trying to run my Haskel fastcgi program with apache (Server version: Apache/2.2.15 (Cent OS 6)),
Following are the changes done in httpd.conf
<IfModule fastcgi_module>
AddHandle fastcgi-script .fcgi
</IfModule>
LoadModule fastcgi_module modules/mod_fastcgi.so
<VirtualHost *:80>
ServerAdmin webmaster#<hostname>
DocumentRoot /var/www
ServerName <hostname>
ErrorLog logs/<hostname>.com-error_log
CustomLog logs/<hostname>-access_log common
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/http">
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler fastcgi-script .fcgi
Order allow,deny
Allow from all
</Directory>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I followed all the instructions as specified here
When I visit the link curl --include http:// hostname/cgi-bin/test.fcgi
I get error in apache server log as
[error] Premature end of script headers: test.fcgi
How can I debug this issue ?

Apache 2.4.1 configuration

I am facing a unique issue. I have setup Apache 2.4.1 and below are my configuration:
ServerRoot "prakash_prasad/bin"
AddHandler cgi-script .py
ScriptAlias /~prakash_prasad/ "/x/home/prakash_prasad/public_html/"
ScriptAlias /test/ "/x/test/prakash_prasad/public_html/"
DocumentRoot "/mybox/prakash_prasad/bin/htdocs"
<Directory "/x/test/*/public_html/">
Options +ExecCGI
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
AddHandler cgi-script .py
SetHandler cgi-script
AllowOverride None
Require all granted
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
</Directory>
<Directory "/x/home/prakash_prasad/public_html/*">
Options +ExecCGI
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
AddHandler cgi-script .py
SetHandler cgi-script
AllowOverride None
Require all granted
</Directory>
Now I have a sample 'first.py' program dumping "Hello World!" which works fine when I enter the below url in the browser
http://:ip/test/first.py
But when I try to load an HTML page:
http://:ip/test/index.html
I get below error in browser:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at you#example.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
while in LOGS I see:
[Thu May 17 23:07:10.664648 2012] [cgid:error] [pid 10386:tid 47977877412864] (13)Permission denied: AH01241: exec of '/x/test/prakash_prasad/public_html/index.html' failed
[Thu May 17 23:07:10.665034 2012] [cgid:error] [pid 9849:tid 1232931136] [client 10.239.40.209:54712] End of script output before headers: index.html
Please let me know what config I need to correct?
::UPDATES::
I narrowed to a point but not sure the issue could be that:
When I comment the cgid module solved the issue for me:
# LoadModule cgid_module modules/mod_cgid.so
My HTML page comes fine but not my Python script
While I uncomment it
LoadModule cgid_module modules/mod_cgid.so
My script works fine but HTML files give error.
Any idea what could the issue be?
With "Options +ExecCGI" directive webserver will treat all files under public_html as an executable. So you have to place your opython files into a separate directory
ScriptAlias /pyfiles/ /home/x/public_html/pyfiles/
Then put your htmls /home/x/public_html/
Try removing the duplicate directives in your configuration since these could be causing an issue i.e for the first Directory:
<Directory "/x/test/*/public_html/">
Options +ExecCGI
Options ExecCGI
Order allow,deny
Allow from all
Options All
SetHandler cgi-script
AddHandler cgi-script .py
AllowOverride None
Require all granted
</Directory>

attempt to invoke directory as script?

is something wrong with my apache config ?
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AllowOverride None
AddHandler cgi-script pl cgi
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
nothing is wrong with your httpd configs, you need to configure httpd to redirect to the directory index. it is literally trying to execute the directory "/etc/www/cgi-bin" as cgi.