Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-13-2011, 11:40 AM   PM User | #1
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
Running CGI-scripts (Python)

How do I make it so that if I go to mysite.com, then it will run the file in cgi-bin/myprog.py?

To add to it, how do I make it so that any file with the extension "py" are not directly viewable, but can be viewed if they go to mysite.com/file_without_extension?
Apothem is offline   Reply With Quote
Old 02-13-2011, 12:09 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Apothem View Post
How do I make it so that if I go to mysite.com, then it will run the file in cgi-bin/myprog.py?

To add to it, how do I make it so that any file with the extension "py" are not directly viewable, but can be viewed if they go to mysite.com/file_without_extension?
assuming that your server is apache:

general information about how to use cgi:
http://httpd.apache.org/docs/2.2/howto/cgi.html

more specific, how to wotk with files extensions:
http://httpd.apache.org/docs/2.2/mod...tml#addhandler

try this steps and post problems:
1. check to have as first line starting with first column of myprog.py this line:
Code:
#!/usr/bin/env python
2. move myprog.py in cgi-bin of the site
3. in cgi-bin directory run from terminal this command:
Code:
chmod 755 myprog.py
4. point your browser to this address: http://localhost/cgi-bin/myprog.py
or http://yourserveraddress/cgi-bin/myprog.py

best regards
oesxyl is offline   Reply With Quote
Old 02-14-2011, 05:07 AM   PM User | #3
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
Is it possible to hide the "cgi-bin" part of the URL?
Apothem is offline   Reply With Quote
Old 02-14-2011, 11:27 AM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Apothem View Post
Is it possible to hide the "cgi-bin" part of the URL?
yes, is usual, one way is to use a rewrite rules

http://httpd.apache.org/docs/2.2/rewrite/

best regards
oesxyl is offline   Reply With Quote
Old 02-14-2011, 09:12 PM   PM User | #5
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
Well, I know a little bit about the rewrite rules, but I do not know of any way to make it so that if the user goes to "<any_file_or_folder>" they will be directed to "cgi-bin/<any_file_or_folder>"...


Also, what is the benefit from having it in the cgi-bin versus outside of it? I have read that it is secure, but how?

Last edited by Apothem; 02-14-2011 at 09:39 PM..
Apothem is offline   Reply With Quote
Old 02-14-2011, 10:59 PM   PM User | #6
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Apothem View Post
Well, I know a little bit about the rewrite rules, but I do not know of any way to make it so that if the user goes to "<any_file_or_folder>" they will be directed to "cgi-bin/<any_file_or_folder>"...

Also, what is the benefit from having it in the cgi-bin versus outside of it? I have read that it is secure, but how?
, you didn't read none of the pages from the links i give it to you, isn't it?

best regards
oesxyl is offline   Reply With Quote
Old 02-14-2011, 11:26 PM   PM User | #7
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
I skimmed it... :P

I mean from what I can understand:
RewriteRule ^/?(.+?) /cgi-bin/$1 [L]

That -should- do what I want... but does that mean it should be in the first line? Last line? As before I thought this would cause an endless loop.
Apothem is offline   Reply With Quote
Old 02-14-2011, 11:39 PM   PM User | #8
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Apothem View Post
I skimmed it... :P

I mean from what I can understand:
RewriteRule ^/?(.+?) /cgi-bin/$1 [L]

That -should- do what I want... but does that mean it should be in the first line? Last line? As before I thought this would cause an endless loop.
rewriting depend on the server settings but usualy this will work:

RewriteRule ^(.+)$ /cgi-bin/myprog.py

now if you have a requests like http://yourserver/apage the cgi script will process the request and in browser address bar you will see http://yourserver/apage and not http://yourserver/cgi-bin/myprog.py.
but, imo, this is only cosmetics and doesn't matter too much.

best regards
oesxyl is offline   Reply With Quote
Old 02-15-2011, 03:12 AM   PM User | #9
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
Well, I read from one of the URLs you gave me related to Python that having the files in the cgi-bin is more secure, though I do not know why. If it wasn't a problem, I would have probably just left the files in the root directory (public_html).
Apothem is offline   Reply With Quote
Old 02-15-2011, 04:05 AM   PM User | #10
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Apothem View Post
Well, I read from one of the URLs you gave me related to Python that having the files in the cgi-bin is more secure, though I do not know why. If it wasn't a problem, I would have probably just left the files in the root directory (public_html).
you can't run cgi script outside of the cgi-bin directory without changing server setting. The document root of the server, public_html, is for everything you want except scripts.

http://www.w3.org/Security/Faq/wwwsf4.html

best regards
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
Apothem (02-15-2011)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:12 AM.


Advertisement
Log in to turn off these ads.