'Two Nginx server block only one works with React app

I want to host several react app on my linux(CentOS) server with nginx.

currently I have two server block in nginx.conf.

First server is where I proxy different request to different server. Second server is my react app.

I couldn't get my react app host by nginx.

Block 1

server {
    listen 80
    server_name localhost
    root /usr/share/nginx/html

    ...
    location /app1/ {
        proxy_pass http://localhost:3010
    }
    ...
}

Block 2

server {
        listen          3010;
        listen          [::]:3010;
        server_name     localhost;
        root            /home/administrator/Projects/app1/build;
        index           index.html index.htm;

        location / {
                try_files $uri $uri/ =404;
        }
    }

When I using telnet to check the server is hosting or not. only port 80 is listening. No server is listening on port 3010.

How should I change my Nginx configuration to make it works?

Update

I check the nginx error log and I got

1862#0: bind() to 0.0.0.0:3010 failed (13: Permission denied)

I've search on it and there are a lot answer about non-root user cannot listen to port below 1024

But the server is trying to bind on 3010

Do I still have to add run nginx by root?



Solution 1:[1]

This is probably related to SELinux security policy. If You check on the below command and see http is only allowed to bind on the list of ports.

[root@localhost]# semanage port -l | grep http_port_t
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000

Maybe you can use any of the listed ports or add your custom port using the below command

$ semanage port -a -t http_port_t  -p tcp 3010

If semanage command is not installed, you can check using yum provides semanage command to identify which package to install.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 redInk