Nginx - running php and node app in the same domain with different ports

3

I'm setting up a blocks in nginx, but I'm having trouble running two separate apps, see the following situation:

  • I have 2 apps (PHP and Node.js)
  • just a domain (example.com) and need to point port 80 for the PHP application and 8080 for the node.js app.
  • I've already done the PHP app pointing and it's ok, but I can not access the app node on the 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 block of node.js

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 anyone tell me what might be wrong, please?

Note: on the server that I am configuring nginx does not have iptables installed and I already tested the application node.js on port 80 and it worked normal.

    
asked by anonymous 30.11.2015 / 15:34

1 answer

1

I was able to find the solution, it was 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 I switched to port 81

2. The server I was configuring has an external firewall, so it blocked other dynamic ports that only worked internally using curl -s domain.com:3000

    
30.11.2015 / 18:34