Nginx - running php app and Node on the same domain with different ports

Asked

Viewed 575 times

3

I am configuring a Blocks in Nginx, but I’m having difficulty running two different apps, see the following situation:

  • I have 2 apps (PHP and Node.js)
  • only one domain (example.com.br) and I need to point port 80 for the PHP application and 8080 for the Node.js app.
  • I’ve already written the PHP app and it’s ok, but I can’t access the Node app in 8080

See my block file for php

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name exemplo.br;

    # root directive should be global
    root   /var/www/app-php/public;
    index  index.php;

    access_log /var/www/app-php/log/access.log;
    error_log  /var/www/app-php/log/error.log;

    client_max_body_size 1024M;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }


    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
   }

   location  ~ /\.ht{
       deny all;
   }

}

And the Node.js block

server {
    listen 8080;

    location / {
            proxy_pass http://localhost:3000;
            # proxy_pass http://127.0.0.1:3000;
            # proxy_pass http://IP-PRIVADO-SERVER:3000;
            # proxy_pass http://exemplo.com.br:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host:8080;
            # proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

}

Can someone tell me what might be wrong, please?

Note: on the server I am configuring the nginx has not iptables installed and already tested the application node.js at the door 80 and worked normal.

1 answer

1


I was able to find the solution, were two problems that were interrupting the execution of this direction.

1. 8080 is an alias of port 80, so it would not be possible to do this for the same domain. Solution switched to port 81

2. the server I was setting up has an external firewall, so it blocked other dynamic ports that only worked internally using Curl -s domain.com.br:3000

  • Kaio, could you send me your contact?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.