Home broadband is configured with a local tomcat server + domain name + ssl + ddns in an ipv6 public network environment to realize functions such as ipv6 station building, simple file server building, and webdav server building

Prerequisites:

        Broadband operators provide ipv6

        The optical modem dial-up is changed to the router dial-up and the router opens ipv6

        The operator has not blocked the 80/443 port of ipv6 (if the common port is blocked, you can try a higher port number. Port number range: 1 - 65535)

Table of contents

1. Alibaba Cloud applies for a domain name & ssl certificate

1. Apply for a domain name

2. Apply for an ssl certificate

Second, configure the tomcat server

1. Download jdk&tomcat

2. Configure jdk&tomcat

3. Configure ssl certificate

4. Open the firewall port

5. Build a website

6. Create a simple file server

7. Create a webdav server

8. Create ddns to realize automatic synchronization of domain name resolution

9. Add tomcat to system services


1. Alibaba Cloud applies for a domain name & ssl certificate

1. Apply for a domain name

Official Website: Alibaba Cloud Enterprise Aviation_Wanwang Domain Name_Industrial and Commercial Finance and Taxation_Intellectual Property Rights_Qualification Records_Intelligent Design_Website Construction-Alibaba Cloud

Domain name price: most of the first year is less than 10 yuan, and the renewal fee is more expensive. If you don't care about the value of the domain name, it is recommended to renew the domain name every year.

2. Apply for an ssl certificate

Official website: Certificate Services_SSL Digital Certificate_HTTPS Encryption_Server Certificate_CA Certification-Alibaba Cloud

Price: You can apply for 20 free ssl certificates within one year, valid for one year. It seems that after the expiration, the free quota will continue to be given every year.

Success time: The system automatically approves, and the application can be successful within 10 minutes. After success, download the ssl certificate and select JKS as the type.

Second, configure the tomcat server

1. Download jdk&tomcat

Download jdk from oracle official website: Java Downloads | Oracle

Choose a jdk version, choose windows, and download the zip package. Of course, you can also download the one-click installation package, then you can skip the subsequent steps of configuring environment variables.

The version I use is jdk17 windows11 zip package.

Apache official website to download tomcat: Apache Tomcat® - Apache Tomcat 11 Software Downloads

Pull to the end of the page, I choose the version is tomcat11: 64-bit Windows zip ( pgp , sha512 )

2. Configure jdk&tomcat

First, decompress the downloaded jdk and tomcat and put them in a fixed path. The path I put is:

C:\Software\jdk-17_windows-x64_bin\jdk-17.0.6

C:\Software\apache-tomcat-11.0.0-M4-windows-x64\apache-tomcat-11.0.0-M4

Windows 11 can directly search for win+s key: environment variables. Windows 10, if I remember correctly, it should be right-clicking on the desktop icon "This Computer" - Properties - Environment Variables

System variables - Create 4 new variables

① Variable name: JAVA_HOME

   Variable value: C:\Software\jdk-17_windows-x64_bin\jdk-17.0.6

Note: There must be a bin folder under the path of C:\Software\jdk-17_windows-x64_bin\jdk-17.0.6, otherwise the path is wrong

②Variable name: TOMCAT_HOME

   Variable value: C:\Software\apache-tomcat-11.0.0-M4-windows-x64\apache-tomcat-11.0.0-M4

③Variable name: CATALINA_HOME

   Variable value: C:\Software\apache-tomcat-11.0.0-M4-windows-x64\apache-tomcat-11.0.0-M4

④ Variable name: CATALINA_BASE

   Variable value: C:\Software\apache-tomcat-11.0.0-M4-windows-x64\apache-tomcat-11.0.0-M4

Similarly, there must be a bin folder under apache-tomcat-11.0.0-M4, otherwise the path is wrong

Find the path under the system variable, double-click to open it, and add:

%JAVA_HOME%\bin

%TOMCAT_HOME%\bin

%CATALINA_BASE%\bin

%CATALINA_HOME%\bin

Try to start tomcat:

        Find startup.bat in C:\Software\apache-tomcat-11.0.0-M4-windows-x64\apache-tomcat-11.0.0-M4\bin and double-click it. If the cmd window does not flash back and is always in front of the window, it is successful. Otherwise, check the environment variable config path.

        Enter http://127.0.01:8080 in the browser, and the tomcat home page appears, which means success.

3. Configure ssl certificate

Place the applied ssl certificate in the conf folder in the tomcat directory

Open the server.xml in the conf directory, find the Connector tag,

        Change the port port to 80

        Add before redirectPort

address="www.abc.com"  
<!-- www.abc.com改为你的域名-->

        Add after the Connector tag

    <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" secure="true" >
        <SSLHostConfig>
                <Certificate certificateKeystoreFile="conf/1234_www.abc.com.jks" 
                    certificateKeystorePassword="abcdef" type="RSA" />

        <!-- conf/1234_www.abc.com.jks 改为证书路径 -->
        <!-- abcdef 改为随证书文件夹下的密码 -->

        </SSLHostConfig>
    </Connector>

Save and restart tomcat.

4. Open the firewall port

Control Panel - System and Security - Windows Defender Firewall - Advanced Settings - Inbound Rules - New Rule

Customize - (next step) - all programs - (next step) - protocol type: TCP; local port: 80 - (click to the end) - give a name and confirm

In the same way, create new tcp and udp protocols on ports 80 and 443.

Test: Access your domain name with a device other than a computer, such as a mobile phone. If the home page of the tomcat you deployed is successfully displayed, it is successful. Otherwise, check the tomcat log, windows firewall, and online port scan to determine whether the carrier has blocked port 80&443.

Tips: Chinese garbled characters may appear in the tomcat log, you need to modify the conf/logging.properties file in the tomcat folder

         Modify java.util.logging.ConsoleHandler.encoding = utf-8 to          

         java.util.logging.ConsoleHandler.encoding = GBK

5. Build a website

        Deploy directly in the webapps\ROOT under the tomcat directory. Of course, you can also create a virtual path:

Create a virtual path:

method one:

        Manually modify conf\server.xml to map the virtual path:

In the server.xml file, insert before the end </Host> tag

<Context path="【Access Path】" docBase="【Actual Path】" debug="0" reloadable="true" />

[Access Path] is changed to:

        / Or leave it blank, which means that after entering the ip or domain name to access, the url does not need to add a path, directly to the directory in the [actual path] folder

        PS: If there is no <Context> tag or the [Access Path] in the tag is left blank, the directory in the webapps/ROOT folder will be automatically accessed.

        /abc means adding /abc after the domain name to access the directory in the [actual path] folder.

【Actual Path】Change to:

        /, means to access the directory in the webapps folder (parallel with the ROOT directory);

        /abc means to access the directory in the webpps/abc folder;

        D:/abc means to access the directory in the abc folder in the D disk (which can be a non-tomcat installation disk).

        PS: tomcat cannot access the root directory of the hard disk partition. For example, after changing [actual path] to D:/ or D:, tomcat cannot actually access any directory

Method Two:

        During actual development, the tomcat installation directory and multiple application directories should be separated into different folders/hard disks.

(CATALINA_HOME: server installation directory, CATALINA_BASE: a web application corresponds to a catalina_base)

        As mentioned above [actual path] when the drive letter is not specified, the directory in the tomcat installation directory webapps is accessed by default.

It is actually possible to modify:

        In the server.xml file will:

        <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">

Modify it to a folder at the same level as webapps or a folder in another hard disk partition .

Then add before </host>: <Context path="" docBase="" debug="0" reloadable="true"/> (if not added, 404 errors cannot be accessed).

        Manually add the xml file and create a virtual path.

        According to the supplementary instructions above, you can create a new [file name 1].xml under CATALINA_BASE/conf/[enginename]/[hostname] (default is tomcat/conf/Catalina/localhost), and add the code:

<Context docBase=" 【actual path】 " /> PS: It seems that only the path can be filled in the actual path. If you fill in the file under the path and omit the file in the url, an error 404 will be reported

        Result: http://domain name/[file name 1], you can access the [actual path].

         Every time you modify the XML file, don't forget to restart Tomcat to make it take effect.

        If tomcat crashes after modification, it means that there is something wrong with the modified xml file, please check one by one.

6. Create a simple file server

find tomcat-conf--web.xml

Search for "servlet" and find

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

Change <param-value>false</param-value> to true.

Add below the </init-param> tag

        <init-param>
            <param-name>readonly</param-name>
            <param-value>true</param-value>
        </init-param>

Then create a virtual path according to the previous title "Building a Station", restart tomcat and use the browser to add the path to access tomcat,

If successful, the browser will display the

7. Create a webdav server

(This is a note from my previous record, I pasted it directly)

The first step, create a new project

① Copy the entire label of service in the server.xml file, and paste service after service;

② Modify the service just pasted, including (service name, port number, Engine name, appBase);

③Copy webapps, paste it in the same directory and rename it webapps02;

④In order to allow ip to access the project, in the connector, add address="[::]";

⑤To be on the safe side, open the directory access authority (web.xml) globally:

The second step, create a configuration file

Create webdav/WEB-INF/web.xml in webapps02 in the first step, and copy the following code into it.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>webdav</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>webdav</servlet-name>
        <servlet-class>org.apache.catalina.servlets.WebdavServlet</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>true</param-value>
        </init-param>
        <!-- Read-Write Access Settings -->
        <init-param>
            <param-name>readonly</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <!-- URL Mapping -->
    <servlet-mapping>
        <servlet-name>webdav</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>webdav</web-resource-name>
            <!-- Detect WebDAV Methods in URL For Whole Application -->
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <!--
            <http-method>GET</http-method>  
            <http-method>PUT</http-method>  
            <http-method>HEAD</http-method>  
            <http-method>TRACE</http-method>  
            <http-method>POST</http-method>  
            <http-method>DELETE</http-method>  
            <http-method>OPTIONS</http-method> 
            -->
            <http-method>PROPFIND</http-method>
            <http-method>PROPPATCH</http-method>
            <http-method>COPY</http-method>
            <http-method>MOVE</http-method>
            <http-method>LOCK</http-method>
            <http-method>UNLOCK</http-method> 
        </web-resource-collection>
        <!-- Restrict access by role -->
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>webdav</realm-name>
    </login-config>
    <security-role>
        <description>WebDAV User</description>
        <role-name>webdav</role-name>
    </security-role>
</web-app>

PS: You can also create webdev (including WEB-INF/web.xml inside) to other hard disk partitions, method:

Open server.xml, under the service corresponding to the project, add

<Context path=""  docBase="D:/webdav" debug="0" reloadable="true" />

In the future, you can directly access the domain name, that is, you can directly access it without adding the /webdav path after the domain name.

Tips: Tomcat seems to have restrictions, probably for security reasons, it is not possible to directly add a whole partition, only a certain subfolder in the partition can be added.

The third step, create a user

Add in apache-tomcat\conf\tomcat-users.xml:

<role rolename="webdav"/> <user username="admin" password="admin" roles="webdav"/>

Test: You can download the Solid Explorer file manager on the Android phone, and create a new cloud connection to check whether it is successful.

8. Create ddns to realize automatic synchronization of domain name resolution

        The github open source project can automatically synchronize the ip address of the computer and resolve the domain name to the dns server.
Project address: GitHub - jeessy2/ddns-go: Simple and easy-to-use DDNS. Automatically update domain name resolution to public network IP (support Alibaba Cloud, Tencent Cloud dnspod, Cloudflare, Callback, Huawei Cloud, Baidu Cloud, Porkbun, GoDaddy, Google Domain)

The general process (refer to the official instructions):
        First, add the program to the service to realize self-starting.

        Then, enter 127.0.0.1:9876 in the browser to enter the configuration interface, and obtain the authority to modify the domain name resolution ip by binding the key of the domain name service provider.

        Finally, realize timing automatic detection whether the local computer ip matches the ip of domain name resolution, and realize the modification function.

       Tips: You can also customize the push modification analysis information through webhook.

9. Add tomcat to system services

        Adding tomcat to the system service can realize self-starting, reduce the cmd window of windows, and start without feeling.

method:

        win + s Search for cmd and run it as an administrator, then enter the bin folder of tomcat with the cd command, execute

        Installation: service.bat install

        Start: net start tomcat11

        Stop: net stop tomcat11

        Query status: sc query tomcat11

        Uninstall: service.bat remove

        Tips:

                The code uses tomcat11 during execution because my installed version is 11. Specifically, you can view cmd to print out the version information of tomat executed during installation.

                Regarding self-starting, check whether the anti-virus housekeeping software prohibits tomcat from starting.

The above tutorials are the tutorials I learned by myself and queried on the Internet, and I have personally deployed them. The websites/tools used include csdn, Github, Baidu, Google, Chatgpt, etc. Thanks for the tutorial shared by the big guys on the Internet, and I also record and summarize my own process, as my own notes and as a reference for friends who love to tinker. If you have any questions, please point out and ask questions. If it helps you, I hope you can like it.

Guess you like

Origin blog.csdn.net/qq_40099123/article/details/130592401