[STEP 1] Nginx Configuration

Nginx Configuration is a complex process. This documentation is optimized and tested for Ubuntu 22.04. If you are using another Linux distribution, the prompts you enter may vary.

First we need to modify the config file of nginx.

$ cd /etc/nginx/
$ nano nginx.conf

We opened the config file of Nginx, in this section we must change sites-enabled to sites-available and save it.

Port forwarding for socket and main site.

This process is complex. It matters where you put the files and which port you start the program from.

$ cd /sites-available
$ rm default
nano domain.com
server {
    server_name domain.com;


  location /images {
    alias /opt/main/public/images/; #file location
    try_files $uri $uri/ =404;
  }


    location / {
        proxy_pass http://localhost:3000; #server portcode
        proxy_read_timeout     60;
        proxy_connect_timeout  60;
        proxy_redirect         off;

        # Allow the use of websockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
nano hsocket.domain.com
server {
    server_name hsocket.domain.com;

    location / {
        proxy_pass http://localhost:3002; #server port
        proxy_read_timeout     60;
        proxy_connect_timeout  60;
        proxy_redirect         off;

        # Allow the use of websockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
nano csocket.domain.com
server {
    server_name csocket.domain.com;

    location / {
        proxy_pass http://localhost:3001; #server port
        proxy_read_timeout     60;
        proxy_connect_timeout  60;
        proxy_redirect         off;

        # Allow the use of websockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

Last updated

Was this helpful?