Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compare mod_Python mode with CGI mode

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article to share with you is about how to mod_Python mode and CGI mode comparison, Xiaobian feel quite practical, so share to everyone to learn, I hope you can read this article after some gains, not much to say, follow Xiaobian to see it.

When running Python script under Apache server, without adding AddHandler cgi-script .py, the content will be displayed in the browser as text text style. I hope this article can bring you some useful information.

Found Apache mod_python version does not support Python 2.6 let alone 3.0.1, only under 2.5, tossing uninstall and install, *** has not been done, put aside first. Now that Python 2.6 is installed and Eric4 supports 2.6, I don't want to reinstall 2.5 to continue configuring mod_python under Apache.

Later, I found an article called Running Python as CGI in Apache in Windows, about running python script in CGI mode instead of mod_python mode. Python for Windows. Open httpd.conf, find "#ScriptInterpreterSource Registry ", remove the previous comment #(if you can't find this line, add it yourself)

Find "Options Indexes FollowSymLinks " and add "ExecCGI " to the end. (The "Indexes "*** can also be removed, because if not removed.) There is no index.html file under the directory, which will show all the files under the directory list, so there is a security vulnerability problem. If you remove Indexes and there is no index.html file, a Forbidden page will be displayed)

Find "AddHandler cgi-script .cgi " followed by.py. If there is no such sentence, you can add "AddHandler cgi-script .py" to restart Apache (sometimes restarting will cause Apache to die, so people who encounter this situation can stop and start again)

Open httpd.conf, find "#ScriptInterpreterSource Registry," remove the previous comment #(if you can't find it, add it yourself), find "Options Indexes FollowSymLinks," and add "ExecCGI " to the end. (The "Indexes "*** can also be removed.)

Because if you don't remove it, there is no index.html file under the directory, and all the files under the directory list will be displayed, so there is a security vulnerability. If you remove Indexes and there is no index.html file, a Forbidden page will be displayed)

Find "AddHandler cgi-script .cgi " followed by.py. If there is no such sentence, you can add "AddHandler cgi-script .py" to restart Apache (sometimes restarting will cause Apache to die, so people who encounter this situation can stop and start again)

Then create a test.py script:

print "Content-type: text/html" print "" print "" print "Hello World" print ""

Note that the second sentence print "" cannot be less, if this sentence is not present, it will cause a "500 Internal Server Error" error. Run http://localhost/test.py in your browser, and the word Hello World is printed to indicate that it works properly. In addition, some error messages are as follows: If ScriptInterpreterSource Registry is not added, a 500 Internal Server Error will appear.

403 Forbidden You don't have permission to access /test.py on this server. Without AddHandler cgi-script.py, the content appears in the browser as text.

Note:

ScriptInterpreterSource Registry was added to allow Windows to use Registry to find Python installation locations. ExecCGI allows python scripts to run in arbitrary directories, because Apache defaults to cgi scripts running in cgi-bin directories.

When I run test.py under htdocs, I get a 403 Forbidden problem. So you need to add ExecuCGI so you can run.py script under htdocs. But ExceCGI has security issues. FastCGI is safer. But the premise is that FastCGI needs to be installed. CGI is slower than mod_python. So try mod_python mode on another computer later.

The above is how to compare mod_Python mode with CGI mode. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report