1. Purchase a server, domain name and register
Now the registration is much simplified. You can download the APP directly and scan it to successfully register.
2. Build the environment
Install Nginx, MySQL, JDK, Tomcat environment on Centos7.3 cloud server
Centos7.6 installation mysql5.5 tutorial
Cenos7.3 install mysql8.0
Centos8.0 compile and install the latest stable version of nginx
Centos7.3 Uninstall Nginx (completely uninstall) and reinstall Nginx (RPM source yum installation)
If you still have questions, please direct Baidu
3. Project deployment
Package the java web project to be uploaded into a war package and upload it to the webapps in the Tomcat directory. When you upload the project's war package before starting Tomcat, it will not be decompressed into a folder. Whenever the projects under Tomcat's webapp are changed (added or deleted), Tomcat must be restarted.
Note: The following commands must be entered into the bin directory of Tomcat to be executed. If you configure the environment variables, you can execute it in any path.
./startup.sh // 启动Tomcat./shutdown.sh // 关闭Tomcat
The war package uploaded to webapp will be parsed into a folder with the same name as the project name. When you open it, there will be a hierarchical structure similar to the project. If your project war package uploaded to webapp has not been Unzip it into a folder with the same name as the project name, that is, you have not restarted Tomcat. First execute the above shutdown command and then execute the startup command.
Enter the decompressed project, you can find that jsp files can be seen in the root directory of the project, and java files such as javabean and lib directories, web.xml or other configuration files exist in the root directory. Under the WEB-INF folder, because the java code will be compiled into class files and stored in the classes folder.
One thing to pay special attention to here is that if the java web project needs to connect to the database on the Linux server, be sure to change the uploaded project in advance to the user name and password of the mysql database on the Linux server and then package it into a war package. Or directly enter the project path change under the Tomcat compiled project under Linux, save the file after completion, then close Tomcat and then start Tomcat.
Project database file import problem
The access address of the project database under Linux remains unchanged, such as:
url = "jdbc:mysql://localhost:3306/数据库名"; 或 url = "jdbc:mysql://127.0.0.1:3306/数据库名"; 或 url = "jdbc:mysql://服务器IP地址:3306/数据库名";
Because the project is uploaded to the server Finally, it is explained that localhost or 127.0.0.1 also represents the local path of the server. Of course, you can also choose to use the public IP of the service, but it is generally not recommended because localhost or 127.0.0.1 at this time represents the server IP at this time.
Navicat, SQLyog or other database visualization tools under local Windows connect to msyql on the Linux server to facilitate direct import of database files on the project.
Import the local mysql database into the mysql database on the Linux server
First, export the database file under Windows and upload it to the server, and then create a server with the same name as the local Windows Database file on
create database 数据库名
Switch to the created database
use 数据库名
Import data
source 上传的数据库文件路径.sql
If you don’t want to be so troublesome, you can also directly use Navicat to connect to mysql on the server. , just import it directly on Navicat.
Nginx reverse proxy accesses the project through the domain name
Resolve the domain name to be used by the project, usually using the second-level domain name for access.
In fact, you can directly use the IP address on the server to access the project. You don’t have to bother using the domain name to access it. But this method not only requires remembering the domain name but also the port number. It is indeed a bit troublesome to deploy too many projects. For example:
IP:8080IP:8081IP:8082或 域名;8080 域名:8081域名:8082
With reverse proxy, you don’t need to add the port every time you access the project. No.
Open the root path of Nginx, switch to conf/, open the nginx.conf file, and add a server module under the http module
The proxy_pass proxy here is the project under the Tomcat server, Tomcat The default port number is 8080, here it is changed to 8010
server { #监听的端口号 listen 80; #一级域名或二级域名 server_name sh.yunxdr.top; #默认文档 index index.jsp index.html index.htm; location / { proxy_pass http://127.0.0.1:8010/项目名/; } }
Note:
Special attention here is the IP address of proxy_pass, which is represented by 127.0.0.1 or localhost When selecting the IP of the server, remember not to use the public IP of the server, because after passing the domain name resolution, using the IP as a proxy to access the secondary domain name cannot be accessed.
proxy_pass can be used here.
http://localhost:8010/Tomcat解析的项目名或 http://127.0.0.1:8010/Tomcat解析的项目名
In order to deploy a Tomcat project in the future, you can copy multiple Tomcats on the Linux server, and then modify the Tomcat default port number so that different project names can be accessed using the second-level domain name.
But you can also deploy multiple projects under one Tomcat. At this time, every time you deploy a new project, the previous projects will be executed again with the startup or shutdown of Tomcat, which consumes a lot of service memory. and CPU will make the server become more stuck. I used this method before deploying projects.
Sometimes after deployment, the project cannot be accessed. This may be because nginx does not recognize the default file. Add the default access path of the project after the agent's project name, such as:
proxy_pass http://127.0.0.1:8010/项目名/index.jsp;
After completing the Nginx configuration, save and exit, and execute the reload command to make the newly configured file take effect.
./nginx -s reload
The execution at this time must be switched to the bin directory of nginx to execute successfully. Unless the environment variables are configured, it can be executed in any path.
At this point the deployment is complete and you can access the project under Tomcat through the domain name. Note that the second-level domain name must be resolved before you can access the project
The above is the detailed content of How to deploy JavaWeb to Linux server. For more information, please follow other related articles on the PHP Chinese website!

The five core components of the Linux operating system are: 1. Kernel, 2. System libraries, 3. System tools, 4. System services, 5. File system. These components work together to ensure the stable and efficient operation of the system, and together form a powerful and flexible operating system.

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
