tomcat is an open source web server. The web based on Tomcat has high running efficiency and can run smoothly on general hardware platforms. Therefore, it is quite popular among webmasters. However, under the default configuration, it has certain security risks and can be attacked maliciously. Here are some security enhancements: Version security Upgrade to the latest stable version. For stability reasons, cross-version upgrades are not recommended. Service demotion Do not use the root user to start Tomcat. Use a normal user to start Tomcat. The user name in the cluster is unified with UID Port protection 1 Change the tomcat management port 8005. This port has the authority to shut down the tomcat service, but the port must be configured between 8000 and 8999, and change the shutdown command. Disable the management terminal 1 Delete the default $CATALINA_HOME/conf/tomcat-users.xml file and restart Tomcat to automatically generate a new file Hide Tomcat version information The display of this information is controlled by a jar package, which is stored in the $CATALINA_HOME/lib directory and is named catalina.jar. Disable automatic war deployment By default, Tomcat enables hot deployment of war packages. In order to prevent the implantation of Trojans and other malicious programs, we need to turn off automatic deployment. Modify the instance:
Custom error pages Edit conf/web.xml and add the following content above the </web-app> tag: <error-page> <error-code>404</error-code> <location>/404.html</location> </error-page> <error-page> <error-code>500</error-code> <location>/500.html</location> </error-page> Shield directory files from being automatically listed Edit the conf/web.xml file <servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <param-value>false</param-value> Here false means not to list, true means to allow listing Multiple virtual hosts It is strongly recommended not to use Tomcat's virtual hosts, and it is recommended to use one instance per site. That is, you can start multiple Tomcats instead of starting one Tomcat containing multiple virtual hosts. Script permission recovery Control the executable permissions of start.sh, catalina.sh, and shutdown.sh in the CATALINAHOME/bin directory Separate Tomcat and project users To prevent Tomcat from being implanted into the web shell program, you can modify the project file. Therefore, we need to separate Tomcat from the project owner, so that even if it is hacked, it will not be able to create and edit project files. Server head rewrite Add server configuration server="server_name" to the HTTP Connector configuration. The default is Apache-Copyote/1.1
Access log format specification <br /> Enable Referer and User-Agent records in the default access log of tomcat Standard Configuration:
Tomcat disables illegal HTTP methods Edit the configuration in the web.xml file <init-param> of org.apache.catalina.servlets.DefaultServlet <param-name>readonly</param-name> <param-value>true</param-value> </init-param> When param-value is true, delete and put operations are not allowed. The tomcat user has remote management permissions <br /> In tomcat-users.xml, modify the role value of the tomcat user to include manager, such as:
The automatic logout time of tomcat is no more than 30 seconds <br /> Edit server.xml and change the automatic logout time to 30 seconds, as follows: <Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75", enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="30000" disableUploadTimeout="true" /> Tomcat should set the minimum and maximum number of connections based on machine performance and business needs. Edit the server.xml file, The example is as follows: <Connector port="8080" minSpareThreads="25" .../> Edit the server.xml file, Tomcat configuration access log <br /> Modify server.xml and uncomment the following content: <Valve className="org.apache.catalina.valves.AccessLogValve" Directory=”logs” prefix=”localhost_access_log.” Suffix=”.txt” Pattern="common" resloveHosts="false"/> Configure Tomcat error page redirection Edit the web.xml file and modify it as follows: <error-page> <error-code>404</error-code> <location>/noFile.htm</location> </error-page> ………… <error-page> <exception-type>java.lang.NullPointerException</exception-type> <location>/error.jsp</location> </error-page> This is the end of this article. The editor of 123WORDPRESS.COM will share more knowledge with you later. You may also be interested in:
|
<<: An example of how to query data in MySQL and update it to another table based on conditions
>>: Implementation of vite+vue3.0+ts+element-plus to quickly build a project
The ".zip" format is used to compress f...
Solution to "Could not run curl-config"...
Table of contents Problem Description What is Vue...
Written at the beginning I remember seeing a shar...
Table of contents aforementioned VARCHAR Type VAR...
In the field of data analysis, database is our go...
The commonly used escape characters in HTML are s...
Problem Description I created three virtual machi...
How to achieve internationalization in React? The...
Table of contents Preface 1. Environment Configur...
The specific code of the sliding button made with...
The reason for writing this article is that I wan...
1. Drop-down list example The code is as follows:...
Original address: https://blog.csdn.net/m0_465798...
introduction If you are familiar with using JDBC ...