1

I tried now for already two days to get my server going... I think I already had like 30 different nginx configs and tried different ports and everything. I'm pretty upset right now because none of the guys doing tutorials for setting up a nginx + node server even mentioned errors, everything seems to work pretty straight forward, but apparently it isn't...

I let the nginx server running with its standard config:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
    listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

    error_page 404 /404.html;
            location = /40x.html {
        }

    error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

which servers me successfully serves me the default test page...

this is my server.js which I'm running via pm2:

var express = require('express'),
  path = require('path'),
  app = express();

//set the port
app.set('port', 3000);

//get node files i need
app.use('/fa', express.static(__dirname + '/node_modules/@fortawesome/fontawesome-free/'));

//tell express that we want to use the www folder
//for our static assets
app.use(express.static(path.join(__dirname, 'www')));

// Listen for requests
var server = app.listen(app.get('port'), function () {
  console.log('The server is running on http://localhost:' + app.get('port'));
});

so the last config I tested was original just with the location block replaced with:

location / {
        proxy_pass http://localhost:3000;
        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;
    }

but i also tested really simple confs like:

events {
    worker_connections 1024;
}

http {
    server {
    listen       80;

        server_name  _;

        location / {
            proxy_pass http://localhost:3000;
            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;
        }   
    }
}

I just dont know what is wrong...

via curl http://localhost:8080 I'm receiving my html but not with my given Server IP...

netstat gives me this:

netstat -tulpn | grep :80
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               
    LISTEN      14841/nginx: master 
    tcp6       0      0 :::80                   :::*                    
    LISTEN      14841/nginx: master

netstat -tulpn | grep :3000
    tcp        0      0 127.0.0.1:3000          0.0.0.0:*               
    LISTEN      14375/node /home/no

BTW.: I'm running fedora 30 and nginx as always via systemctl and pm2 as non-root user via pm2 start server.js. I also use UFW and disabled firwalld, but WWW is allowed in ufw...

I really appreciate all the help and advice's u guys can give me.

I simply dont know what to do :(...

jshAMG
  • 23
  • 8
  • What does the NGINX logs say? – d4nyll Jun 06 '19 at 14:45
  • Oh and btw if it is necessary, the app is a very heavy 3D rendering thing, so I thought it could be that so timeout or data limits be exceeded, but I have no idea to figure that out by now and I don't now if that's really a thing... – jshAMG Jun 06 '19 at 14:47
  • this is the access log for a request: ```77.191.179.164 - - [06/Jun/2019:14:48:15 +0000] "GET / HTTP/1.1" 502 3693 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "-" 77.191.179.164 - - [06/Jun/2019:14:48:15 +0000] "GET /nginx-logo.png HTTP/1.1" 502 3693 "http://140.82.47.236/" "Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "-"``` – jshAMG Jun 06 '19 at 14:49
  • ```77.191.179.164 - - [06/Jun/2019:14:48:15 +0000] "GET /poweredby.png HTTP/1.1" 502 3693 "http://140.82.47.236/" "Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "-" 77.191.179.164 - - [06/Jun/2019:14:48:16 +0000] "GET /favicon.ico HTTP/1.1" 502 3693 "http://140.82.47.236/" "Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "-" ``` – jshAMG Jun 06 '19 at 14:52
  • and this is the error log for a request: ```2019/06/06 14:50:57 [crit] 15010#0: *20 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 77.191.179.164, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "140.82.47.236" 2019/06/06 14:50:57 [crit] 15010#0: *20 connect() to [::1]:3000 failed (13: Permission denied) while connecting to upstream, client: 77.191.179.164, server: _, request: "GET / HTTP/1.1", upstream: "http://[::1]:3000/", host: "140.82.47.236" 2019/06/06``` – jshAMG Jun 06 '19 at 14:53
  • ```14:50:57 [error] 15010#0: *20 no live upstreams while connecting to upstream, client: 77.191.179.164, server: _, request: "GET /nginx-logo.png HTTP/1.1", upstream: "http://localhost/nginx-logo.png", host: "140.82.47.236", referrer: "http://140.82.47.236/" 2019/06/06 14:50:57 [error] 15010#0: *23 no live upstreams while connecting to upstream, client: 77.191.179.164, server: _, request: "GET /poweredby.png HTTP/1.1", upstream: "http://localhost/poweredby.png", host: "140.82.47.236", referrer: "http://140.82.47.236/" 2019/06/06 ``` – jshAMG Jun 06 '19 at 14:53
  • ```14:50:57 [error] 15010#0: *20 no live upstreams while connecting to upstream, client: 77.191.179.164, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://localhost/favicon.ico", host: "140.82.47.236", referrer: "http://140.82.47.236/" ``` seems like some permission problem but i have no idea... sorry somehow i was limited in characters... – jshAMG Jun 06 '19 at 14:53
  • Is your node program active? I've got a feeling it might terminating itself upon receiving a request. – suv Jun 06 '19 at 14:54
  • no i dont think so pm2 monitor is monitoring it, it is still running, it works on my pc on my local net, too... – jshAMG Jun 06 '19 at 14:58
  • You mean to say, that if you directly open localhost:3000, then your request is fulfilled? Only through nginx its an issue? – suv Jun 06 '19 at 14:58
  • @suv correctly, i can curl http://localhost:3000 on that external machine and got my html code in response – jshAMG Jun 06 '19 at 15:06
  • I just noticed if I curl xxx.xxx.xxx.xxx my external machine on THAT MACHINE it is responding with the html too but not on my pc here at home – jshAMG Jun 06 '19 at 15:09
  • HAHAHAHA ok i noticed I can curl the Ip from my local machine, too and got the html in response, bot not through the browser... – jshAMG Jun 06 '19 at 15:11

1 Answers1

0

Ok i figured out now. It was an SELinux rule error. Denying me to connect to my server by http.

setsebool httpd_can_network_connect on -P

fixed it permanently. This post answered my Question:

(13: Permission denied) while connecting to upstream:[nginx]

Greetings, Josh.

If you want you can check the page out, warning its 18+ content :D I know there is a canvas Bug with IOs devices, not working there. And because of the heavy Assets i would not recommend you using a limited Data Plan (about 70Mb of 3D asset). Contact me if it's working or not (its just an experiment for sth bigger :) ). IP is: 140.82.47.236

jshAMG
  • 23
  • 8