来源:蜘蛛抓取(WebSpider)
时间:2016-05-05 09:51
标签:
apn切换是什么意思
mod python - 404 error while executing .py file in cgi-bin using apache2 - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
previously i had error in installing apache2 for python,
I thought i should continue there but right now i'm getting a new error so posting it as a new one this is what the problem is
I have placed a file hello.py having code
#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print '&html&'
print '&head&'
print '&title&Hello Word - First CGI Program&/title&'
print '&/head&'
print '&body&'
print '&h2&Hello Word! This is my first CGI program&/h2&'
print '&/body&'
print '&/html&'
in a folder /var/www/cgi-bin when I run this on apache2 using
i'm getting this error
The requested URL /cgi-bin/hello.py was not found on this server. Apache/2.2.14(Ubuntu)Server at localhost Port 80
This is the code that i found in the default page in sites-available folder:
&VirtualHost *:80&
ServerAdmin webmaster@localhost
DocumentRoot /var/www
&Directory /&
Options FollowSymLinks
AllowOverride None
&/Directory&
&Directory /var/www/&
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
&/Directory&
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
&Directory "/usr/lib/cgi-bin"&
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
&/Directory&
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
&Directory "/usr/share/doc/"&
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
&/Directory&
&/VirtualHost&
This is what i could find in the error log:
[Fri May 06 13:41:22 2011] [notice] mod_python: using mutex_directory /tmp
[Fri May 06 13:41:22 2011] [notice] Apache/2.2.14 (Ubuntu) mod_python/3.3.1 Python/2.6.5 mod_wsgi/2.8 configured -- resuming normal operations
[Fri May 06 14:23:03 2011] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri May 06 14:23:03 2011] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 284 to 218 : URL /favicon.ico
[Fri May 06 14:23:11 2011] [notice] mod_python (pid=2038, interpreter='127.0.1.1'): Importing module '/var/www/cgi-bin/hello.py'
[Fri May 06 14:23:11 2011] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 289 to 222 : URL /cgi-bin/hello.py
[Fri May 06 14:23:11 2011] [error] /usr/lib/python2.6/dist-packages/mod_python/importer.py:32: DeprecationWarning: the md5
use hashlib instead
[Fri May 06 14:23:11 2011] [error]
import md5
[Fri May 06 14:23:25 2011] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 289 to 222 : URL /cgi-bin/hello.py
This is what i could find in access.log:
172.16.0.73 - - [06/May/:02 +0530] "GET / HTTP/1.1" 200 492 "-" "EZI_WIN_HTTP_AGENT"
172.16.0.73 - - [06/May/:47 +0530] "GET / HTTP/1.1" 200 492 "-" "EZI_WIN_HTTP_AGENT"
127.0.0.1 - - [06/May/:03 +0530] "GET /favicon.ico HTTP/1.1" 404 501 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/ Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/:10 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 504 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/ Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/:25 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 504 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/ Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/:33 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 505 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/ Ubuntu/10.04 (lucid) Firefox/3.6.3"
125.224.195.218 - - [06/May/:10 +0530] "CONNECT 203.188.201.253:25 HTTP/1.1" 405 539 "-" "-"
172.16.0.25 - - [06/May/:53 +0530] "HEAD / HTTP/1.0" 200 277 "-" "-"
127.0.0.1 - - [06/May/:32 +0530] "GET /cgi-bin/hello.py HTTP/1.1" 404 505 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/ Ubuntu/10.04 (lucid) Firefox/3.6.3"
127.0.0.1 - - [06/May/:35 +0530] "GET /favicon.ico HTTP/1.1" 404 500 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/ Ubuntu/10.04 (lucid) Firefox/3.6.3"
Please help me through this.
In your Apache configuration, you need to change the Directory directive to: &Directory /var/www/cgi-bin& if this is where you intend to host your mod_python scripts.
You're placing your python script in /var/www/cgi-bin but /cgi-bin/ is defined to point to /usr/lib/cgi-bin.
You need to standardize on one location for /cgi-bin/.
Here's what I would propose as your corrected Apache configuration.
Note that I didn't remove any lines, I only commented out the lines that are not needed or have been replaced.
&VirtualHost *:80&
ServerAdmin webmaster@localhost
DocumentRoot /var/www
&Directory /&
Options FollowSymLinks
AllowOverride None
&/Directory&
#&Directory /var/www&
&Directory /var/www/cgi-bin&
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
&/Directory&
#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#&Directory "/usr/lib/cgi-bin"&
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
#&/Directory&
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
&Directory "/usr/share/doc/"&
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
&/Directory&
&/VirtualHost&
Now that your Apache configuration is correct, and we've verified that your module is importing correctly, you're still getting a 404.
This is because you are using the mod_python publisher handler, which expects a different usage than what you have implemented.
Basically, you have implemented a simple CGI script that just prints output.
mod_python has a specific API for executing your module.
You should
to get an understanding of how it works.
To implement your test module as a valid mod_python publisher, you could change hello.py to this:
def index(req):
return """&html&
&title&Hello Word - First CGI Program&/title&
&h2&Hello Word! This is my first CGI program&/h2&
&/html&"""
Note that the reason you were getting a 404 error (even though the module was imported) is explained on :
The traversal will stop and
HTTP_NOT_FOUND will be returned to the
client if:
Any of the traversed object's names
begin with an underscore ("_"). Use
underscores to protect objects that
should not be accessible from the web.
A module is encountered. Published
objects cannot be modules for security
If an object in the path could not be
found, HTTP_NOT_FOUND is returned to
the client.
15.7k74970
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled