realease lần 1

This commit is contained in:
NAS\NASPC
2026-06-09 08:09:51 +07:00
parent ee6b2a8919
commit 9b6e188df8
19 changed files with 3638 additions and 3118 deletions
+58 -43
View File
@@ -186,67 +186,82 @@ To configure CI for your project, run the ci-cd sub-generator (`jhipster ci-cd`)
- [Node.js](https://nodejs.org/)
- [NPM](https://www.npmjs.com/)
## Deployment Guide (Ubuntu server + aaPanel + Docker)
## Deployment Guide (Ubuntu server + aaPanel + Executable JAR)
### 1. Build the WAR file (on Windows)
To deploy this application to an external Tomcat server, you need to build a `.war` file.
Run the following command on your Windows PC to build the production-ready `.war` file:
### 1. Build the JAR file (on Windows)
Spring Boot applications come with a built-in web server, meaning you can package your entire application into a single executable `.jar` file!
Run the following command on your Windows PC to build the production-ready `.jar` file:
```powershell
./gradlew -Pprod -Pwar clean bootWar
./gradlew -Pprod clean bootJar
```
Alternatively, you can use the built-in npm script:
```powershell
npm run java:war:prod
npm run java:jar:prod
```
The generated `.war` file will be located at `build/libs/sisvietnamvn-0.0.1-SNAPSHOT.war`.
The generated `.jar` file will be located at `build/libs/sisvietnamvn-1.0.3.jar`.
### 2. Standalone Tomcat 10 using Docker Compose (on Ubuntu Server)
Since this project uses Java 21, it requires **Tomcat 10.1**. You can set this up on your Ubuntu server using Docker Compose.
### 2. Deploy and Run the application (on Ubuntu Server)
Create a folder for Tomcat, and add a `docker-compose.yml` file:
```yaml
version: '3.8'
You have two main options to run the application on Ubuntu: using **aaPanel** or using standard **systemd**.
services:
tomcat:
image: tomcat:10.1-jdk21
container_name: my-tomcat-server
ports:
- "8080:8080"
environment:
- TZ=Asia/Ho_Chi_Minh
volumes:
- ./webapps:/usr/local/tomcat/webapps
- ./logs:/usr/local/tomcat/logs
restart: unless-stopped
```
#### Option A: Using aaPanel (Recommended)
If you are using aaPanel, it is highly recommended to use its built-in **Java Project** manager to easily run the JAR file.
Create the required folders and start the server:
```bash
mkdir webapps logs
docker compose up -d
```
1. **Install Java 21**: Make sure Java 21 is installed on your Ubuntu server via aaPanel.
2. **Upload the JAR**: Upload the `sisvietnamvn-1.0.3.jar` file to a folder on your server (e.g., `/www/wwwroot/sisvietnam.vn/`).
3. **Add Java Project**: In aaPanel, go to **Website** -> **Java Project** -> **Add Java project**.
4. **Configure Project**:
- **Project Type**: `Spring_boot`
- **Project jar**: Select the `sisvietnamvn-1.0.3.jar` file you just uploaded.
- **Project Port**: `8080` (or whichever port your app is configured to use).
- **Run user**: `www` (or `root`)
- Click **Submit**. aaPanel will automatically run your JAR file in the background!
### 3. Deploy the application
After running the build command successfully, your .war file is located here:
d:\website_sisvietnam_moi\website_sisvietnam.vn\sisvietnamvn\build\libs\sisvietnamvn-0.0.1-SNAPSHOT.war
(Inside your project folder, look for the build folder, then open the libs folder).
This sisvietnamvn-0.0.1-SNAPSHOT.war file is the one you need to upload to your Ubuntu server and rename to ROOT.war inside the Tomcat webapps folder.
#### Option B: Using systemd (Standard Ubuntu)
If you prefer managing the server manually via terminal, you can register the JAR as a `systemd` service so it runs continuously in the background and starts automatically on boot.
Upload the `.war` file you built in Step 1 to the server.
Place it inside the `webapps/` folder you just created and rename it to `ROOT.war` (so it serves on the root path `/`). Tomcat will automatically detect and deploy it.
1. **Upload the JAR**: Upload the `sisvietnamvn-1.0.3.jar` file to your server (e.g., `/var/www/sisvietnam/sisvietnamvn.jar`).
2. **Create the Service File**:
```bash
sudo nano /etc/systemd/system/sisvietnam.service
```
3. **Add Configuration**: Paste the following, making sure the `ExecStart` path matches where you put the jar.
```ini
[Unit]
Description=SIS Vietnam Spring Boot Application
After=syslog.target network.target
### 4. Configure NGINX Reverse Proxy (aaPanel)
Using NGINX (via aaPanel) with Tomcat is a highly recommended setup. NGINX acts as a Reverse Proxy, handling internet traffic (ports 80 and 443 for SSL) and forwarding it to Tomcat on port 8080.
[Service]
User=root
ExecStart=/usr/bin/java -jar /var/www/sisvietnam/sisvietnamvn.jar
SuccessExitStatus=143
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
```
4. **Start the Service**: Run the following commands to reload systemd, enable the service to start on boot, and start it now:
```bash
sudo systemctl daemon-reload
sudo systemctl enable sisvietnam.service
sudo systemctl start sisvietnam.service
```
5. **Check Status & Logs**:
- To check if it's running: `sudo systemctl status sisvietnam.service`
- To view the live terminal output: `sudo journalctl -u sisvietnam.service -f`
### 3. Configure NGINX Reverse Proxy (aaPanel)
When you set up a Java Project in aaPanel, it can automatically map your domain and set up a reverse proxy. If you need to verify or set it up manually:
1. **Add Site**: Go to aaPanel -> Website -> Add site. Enter your domain (e.g., `sisvietnam.vn`) and select **Static** for the PHP version.
2. **Setup Reverse Proxy**: Click "Settings" for the new site -> "Reverse proxy" -> "Add reverse proxy".
- **Proxy name**: `TomcatProxy`
2. **Setup Reverse Proxy**: Click "Settings" for the site -> "Reverse proxy" -> "Add reverse proxy".
- **Proxy name**: `JavaProxy`
- **Target URL**: `http://127.0.0.1:8080`
- **Sent Domain**: `$host`
3. **Spring Boot Proxy Trust**: Ensure Spring Boot knows it is behind a proxy so it can read client IPs and HTTP schemes correctly. In `src/main/resources/config/application-prod.yml`, verify this exists:
3. **Spring Boot Proxy Trust**: Ensure Spring Boot knows it is behind a proxy so it can read client IPs correctly. In `src/main/resources/config/application-prod.yml`, verify this exists:
```yaml
server:
forward-headers-strategy: framework
```
4. **SSL**: Use aaPanel's built-in SSL manager to apply Let's Encrypt certificates to your NGINX site. Your Tomcat backend won't need to worry about SSL certificates.
4. **SSL**: Use aaPanel's built-in SSL manager to apply Let's Encrypt certificates to your NGINX site. You don't need to configure SSL inside Spring Boot itself.