Backend server for a chat app.
-
MySQL 8.0 server
-
JRE 17
Login to MySQL as root
CREATE DATABASE ghost_chat;
CREATE USER 'ghost_chat_user'@'localhost' IDENTIFIED BY '1234';
GRANT ALL ON ghost_chat.* TO 'ghost_chat_user'@'localhost';Before running the application, please make sure your system environment meets the prerequisites described above and have the database configured.
cd into project root
./mvnw spring-boot:runIt can take a while when you run it for the first time, since maven would resolve and download dependencies.
Alternatively, run the program using jar file:
java -jar chat-server-xxx.jar./mvnw installPackaged jar file will be located under chat-server/target/.
Spring Boot application default listens on port 8080, and in this application, all APIs have url starting with /api.
In this case, we want all requests to http://server/api/ to be forwarded to the same machine but a different port http://server:8080/api/.
-
Edit the
/etc/nginx/nginx.conffile and add the following settings to the server block that should provide the reverse proxy:location /api/ { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header X-Forwarded-Proto $scheme; }
-
If nginx is running on RHEL based distributions, set the
httpd_can_network_connectSELinux boolean parameter to1to configure that SELinux allows NGINX to forward traffic:setsebool -P httpd_can_network_connect 1
-
Restart the
nginxservice:systemctl restart nginx
Run the program with the frontend and reverse proxy set up. Visit http://server/api to read Rest API documentation.