现在的位置: 首页 > 综合 > 正文

Add new URL for CGI in Apache

2013年05月15日 ⁄ 综合 ⁄ 共 2772字 ⁄ 字号 评论关闭

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”.

 

 

抱歉!评论已关闭.