Add new URL for CGI in Apache

There is a DocumentRoot tag in httpd.conf to let you change the directory for your files. However, you can set up a new directory outside of your DocumentRoot directory for your specific purpose. Why? This can provide as little information as possible to the outside of world. The less a hacker knows about where your programs are physically located, the less harm that person can do.

 

First, you create a directory outside your DocumentRoot directory. For example,  /var/myexample.

 

Second, create a alias for your directory, you can use the Alias for your common directories or ScriptAlias for your CGI program directories:

              ScriptAlias        /cgi-bib/        “/var/myexample/cgi/”   or

              Alias               /jsp/        “/var/myexample/jsp/”

If you are setting up the directory support virtual site, add the Alias or ScriptAlias in the <VirtualHost…> container that defines the host.

              <VirtualHost        10.26.24.3>

                     ServerName           new.domain.com

                     DocumentRoot       /var/www/html

                     Alias                     /jsp/        “/var/myexample/jsp/”

              </VirtualHost>

 

Third, create a <Directory> container for that directory.

              <Directory        “/var/myexample/jsp/”>

                     Options        ExecCGI       -Indexes

                     AddHandler       cgi-script        .pl

              </Directory>

The Options directive sets two options for the “/var/myexample/jsp/” directoyr. First, the ExecCGI is set, which tells apache to permit CGI program execution from within this directory. Second, the –Indexes tells apache that don’t list the files and directories under this directory, since because it is not a good idea to allow visitors to see the contents of your CGI script directory. Next, the AddHandler directive sets the cgi-script handler for a list of file extensions found in this directory. Any file with the named extension in the list is treated as a CGI program.

 

If you have virtual site, you can add these in the <VirtualHost…> directive:

              <VirtualHost       10.26.24.3>

                     ServerName           new.domain.com

                     DocumentRoot       /var/www/html

                     Alias                     /jsp/        “/var/myexample/jsp/”

                     <Directory        “/var/myexample/jsp/”>

                     Options        ExecCGI       -Indexes

                     AddHandler       cgi-script        .pl

                     </Directory>

              </VirtualHost>

 

Then, you can visit your Web Server by typing “ http://your-server-name/jsp/ “.

Note: You’d better take more attention for the slash “/” at the end of your alias name. Both of the original name and alias name, for example Alias /jsp/ “/var/myexample/jsp/”, should have slash (as show before) or don’t have the slash such as: Alias /jsp “/var/myexample/jsp”. Because, if you define your alias name as: Alias /jsp/ “/var/myexample/jsp”, when you type the URL “ http://localhost/jsp/index.html “ in your browser, the apache server will translate it to “/var/myexample/jspindex.html” instead of “/var/myexample/jsp/index.html”.

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值