Tomcat configuration skills TOP 10 (3)

xiaoxiao2021-03-06  66

7. Configure user custom directory (Customized User Directores)

Some sites allow individual users to publish web pages on the server. For example, a university's college may want to give every student a public area, or an ISP hopes to give some clients to his client, but this is not a virtual host. In this case, a typical method is to add a special character (~) in front of the username, as a website of each user, such as:

http://www.cs.myuniversity.edu/~username

Http://members.mybigisp.com/~username

Tomcat provides two ways to shoot these personal websites on the host, mainly using a special Listener element. Listener's classname property should be org.apache.catalina.startup.userConfig, the UserClass property should be one of several mapping classes. If your system is UNIX, it will have a standard / etc / passwd file that can be readily read by the account in the file, which specifies the user's home directory, using the PasswduSerDatabase map class.

DIRECTORYNAME = "public_html"

Userclass = "org.apache.catalina.startup.passwduserDatabase" />

The web file needs to be placed under the directory of / home / users / ian / public_html or / users / jbrittain / public_html. Of course, you can also change public_html to any other subdirectory.

In fact, this user directory does not necessarily need to be in the user's home directory. If you don't have a password file, you want to map a username to the subdirectory of the public image / home, you can use the HomesUserDatabase class.

DirectoryName = "public_html" HomeBase = "/ home"

Userclass = "org.apache.catalina.startup.homesuserDatabase" />

In this way, the web file can be located in the same directory like / home / jasonb / public_html. This form is more advantageous for Windows, you can use a directory like C: / HOME.

These Listener elements, if they appear, must be in the Host element, and cannot be in the Context element, because they are used in Host itself.

8. Use the CGI script in Tomcat

Tomcat is primarily as a servlet / jsp container, but it also has many traditional web servers. Support for universal gateway interfaces (CGI) is one of them, CGI provides a set of methods to run some extensions when responding to browser requests. The reason why CGI is called generic because it can be called in most programs or scripts, including: Perl, Python, awk, unix shell scripting, etc., even Java. Of course, you probably not run a Java application as a CGI, after all, this is too primitive. In general, development servlets are always better than CGI, because when the user clicks on a link or a button, you do not need to start from the operating system layer. Tomcat includes an optional CGI servlet that allows you to run the CGI script left.

In order to enable Tomcat to run CGI, you have to do the following things:

1. Remove servlets-cgi.renametojar (in catalina_home / server / lib / directory) to servlets-cgi.jar. Handling the servlet of CGI should be located under the classpath of Tomcat.

2. In Tomcat's Catalina_Base / Conf / Web.xml file,

Note Remove the paragraph of CGI (by default, this paragraph is located 241).

3. Similarly, in Tomcat's Catalina_Base / Conf / Web.xml file, the annotation of the paragraph of mapping of CGI is removed (by default, this paragraph is located 299). Note that this content specifies how HTML links to the CGI script.

4. You can place the CGI script in a web-inf / cgi directory (note that web-inf is a safe place, you can put some files that don't want to be seen or safe to expose by the user), Or you can also place the CGI script in other directories under Context and adjust the CGIPATHPREFIX initialization parameters for the CGI Servlet. This is the actual location of the specified CGI Servlet and cannot be rename with the URL specified by the previous step.

5. Restart Tomcat, your CGI can run.

In Tomcat, the CGI program is default in the web-INF / CGI directory. As mentioned earlier, the web-INF directory is protected, and the browser through the client cannot spy to the content, so for the placement of the password or This is a very nice place for CGI scripts of other sensitive information. To be compatible with other servers, although you can also save the CGI script in the traditional / cgi-bin directory, you have to know that the files in these directories may be seen by the curious surfers on the Internet. In addition, in UNIX, determine that the user who runs Tomcat has permission to perform the CGI script.

9. Change the JSP compiler in Tomcat (JSP Compiler)

In Tomcat 4.1 (or higher, probably), JSP compiling is performed directly by the ANT controller included in Tomcat. This sounds a little strange, but this is part of ANT intention to use, and an API document guides developers using Ant without launching a new JVM. This is a major advantage in Java development using Ant. In addition, this also means that you can now use any Javac support in Ant, here there is a Javac page list about the APACHE ANT User Manual. It is easy to use because you only need to define a name "Compiler" in the element, and there is a compiler name supported in Value. Examples are as follows:

JSP

Org.apache.jasper.Servlet.jspservlet

logverbositylevel

Warning

compiler

jikes

3

Of course, given the compiler must already be installed in your system, and ClassPath may need to set, which is done in what compiler you choose.

10. Restricting a specific host access (Restricting Access To Specific Hosts)

Sometimes you might want to limit access to Tomcat web applications, for example, you want only your host or IP address to access your app. In this way, only those specified clients can access the content of the service. To achieve this effect, Tomcat provides two parameters for you to configure: RemotehostValve and RemoteadDrvalve.

By configuring these two parameters, you can filter from the requested host or IP address and allow or reject which host / IP. Similarly, there is a permission / rejection specified for each directory in the HTTPD file in Apache.

For example, you can set the Admin Web Application to allow local access, set as follows:

Allow = "127.0.0.1" deny = "" />

If you do not give the host's designation, the host that does not match the host will be rejected, which is allowed to be allowed. Similarly, if the designation of the reject host is not given, the host that is allowed to match the host will be allowed, in addition to the rejection. (T111)

<< Previous page 1 2 3

转载请注明原文地址:https://www.9cbs.com/read-88262.html

New Post(0)