Skip to content

hu-ximing/chat-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chat Server

Overview

Backend server for a chat app.

Frontend

Prerequisites

  • MySQL 8.0 server

  • JRE 17

Configuring database

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

Running the application

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

It 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

Building from source

./mvnw install

Packaged jar file will be located under chat-server/target/.

Deploying behind Nginx reverse proxy

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

  1. Edit the /etc/nginx/nginx.conf file 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;
    }
  2. If nginx is running on RHEL based distributions, set the httpd_can_network_connect SELinux boolean parameter to 1 to configure that SELinux allows NGINX to forward traffic:

    Learn more

    setsebool -P httpd_can_network_connect 1
  3. Restart the nginx service:

    systemctl restart nginx

Rest API

Run the program with the frontend and reverse proxy set up. Visit http://server/api to read Rest API documentation.

About

Backend server for a chat app

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published