Set Up CommunitySet Up ChatPlus SolutionSet up reverse proxy with NginX

Set up reverse proxy with NginX

Assume that you would like to set up Chatplus with 2 subdomains chat.yourdomain.com and voip.yourdomain.com . Here are NginX configurations for ChatPlus:

Chat

Create a new NginX configuration file for ChatPlus, such as at /etc/nginx/conf.d/chatplus.conf and add the following content into the file. Then, save it.

upstream chat_backend {
    server 127.0.0.1:3000;
}

# HTTPS Server
server {
    server_name chat.yourdomain.com;

    # You can increase the limit if your need to.
    client_max_body_size 200M;

    error_log /var/log/nginx/chat.yourdomain.com.error.log;
    add_header Accept-Ranges bytes;

    location / {
        proxy_pass http://chat_backend/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;
        proxy_force_ranges on;

        proxy_redirect off;
    }

    listen 80;
}

Video Bridge

Create a new NginX configuration file for Call/VoIP server, such as at /etc/nginx/conf.d/voip.conf and add the following content into the file. Then, save it.

upstream voip_backend {
    server 127.0.0.1:8443;
}

# VoIP server
server {
    server_name voip.yourdomain.com;

    # You can increase the limit if your need to.
    client_max_body_size 200M;

    error_log /var/log/nginx/voip.yourdomain.com.error.log;

    location / {
        proxy_pass https://voip_backend/;
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }

    location /xmpp-websocket {
        proxy_pass https://voip_backend/xmpp-websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location /colibri-ws/ {
        proxy_pass https://voip_backend/colibri-ws/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    listen 80;
}

Note that SSL configuration is not included in the above NginX configuration. You can set up SSL for your subdomains with your preferred method, such as with Certbot or with other SSL providers. After setting up SSL, you will need to update the above NginX configuration to listen on port 443 and add SSL related configuration such as ssl_certificate and ssl_certificate_key for each server block.

After adding the above configuration, run following command to check if there is any error in NginX configuration. If there is no error, you will see “syntax is ok” and “test is successful” messages.

nginx -t

Then, run following command to reload NginX configuration

systemctl reload nginx

Done! You have successfully set up NginX as reverse proxy for ChatPlus server. You can check if the reverse proxy is working properly by accessing to ChatPlus server with the subdomain URL, such as https://chat.yourdomain.com and https://voip.yourdomain.com