Nginx reverse proxy mapping does not redirect - node.js

I recently started tinkering to solve this problem I was having this problem. So I installed NGINX and set it up so that it forwards the incoming requests on port 80 to port 300 by creating a .conf file in /etc/nginx/conf.d/ location. Here is the configuration file.
server {
listen 80;
server_name xyz.xyz;
location / {
proxy_pass http://127.0.0.1:300;
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 when I hit xyz.xyz I get the default page and when I go to xyz.xyz:300 I get my NodeJS app. Any suggestion?

Seems like it was an issue with SELinux.
I just ran this command and it worked.
setsebool -P httpd_can_network_connect 1

Related

Nginx setup for Node Media Server

I'm trying to run node-media-server on a EC2 instance, but i a'm not able to make OBS to connect to the server, here is my Nginx config:
server {
listen 8000;
listen 1935;
server_name example.com;
location / {
proxy_pass http://localhost:$server_port;
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;
}
}
And here is my security group set up:
Any idea what is going on?
Thanks in advance,
I found the problem, the first thing is to setup Nginx to listen on the port 80 only as node-media-server takes care of listening on the ports 8000 and 1935
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:$server_port;
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;
}
}
Second thing is to make sure the ports 8000 and 1935 are open in the server as by default they are not.
Hope it helps to anyone with the same problem.

nginx with two node aplications with socket IO

I have two applications running on the same machine. One listens on port 8080 and the other on 11180. SSL connection to the application on port 8080 works but i am having trouble setting up the other one.
To separate the requests heading to each of the applications, one is available at https://example.com and the other at https://example.com/v2
As I said, going to https://example.com works as intended, but going to https://example.com/v2 serves the correct html files but connects to the same server as going to https://example.com
I honestly have no idea what i am doing with nginx, but my config looks like this.
server {
listen 443 ssl;
location / {
proxy_pass http://127.0.0.1:8080;
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;
}
location /v2/ {
proxy_pass http://127.0.0.1:11180/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
}
location /socket.io {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
#proxy_redirect off;
}
}
It is worth mentioning that the first app listens on 8080 and its socket io on 8081, as for the second app, everything listens on 11180
Thanks a bunch in advance
I ended up adding another server block to the nginx config, and accessing it via www.example.com:port.
As the accepted answer say you could create a new server block... or you can even create a new conf file in the sites-available folder for the new domain with a new server block. Dont forget to link them to sites-enabled.

Cannot reach Node.js application over HTTPS

I have an node.js application that is running on port 3000.
Infront of it i run an nginx reverse proxy. It works fine for port 80. I have tried to install an certificate with certbot. Now i have the certificate and set up my proxy to redirect all non HTTPS traffic to HTTPS and on the port 443 i listent to it and pass my connection to my application. Somehow my browser is pending and i dont know why.
Here i have added 2 server blocks:
server {
server_name mywebsite.at www.mywebsite.at;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/mywebsite.at/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.at/privkey.pem;
location / {
proxy_pass http://127.0.0.1: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;
}
}
server {
server_name mywebsite.at www.mywebsite.at;
listen 80;
location / {
proxy_pass http://127.0.0.1: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;
}
}
In this case i can enter http://mywebsite.at but i cant enter https://mywebsite.at. It says "cant reach the website". Any idea why this error appears?
I have runned sudo nginx -t there are no erros.
I have found the problem guys. My port 443 was not open. ufw allow 443 fixed the issue.

Nginx screen appering on first request to the domain

The first requests in the browser to this following API's are appering the Nginx screen.
Goeat Api GympointApi
Idk what is wrong on my proxy configuration
server {
listen 80;
server_name gympoint.lauradeveloper.com.br;
location / {
proxy_pass http://localhost:3333;
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;
}
}
server {
listen 80;
server_name goeat.lauradeveloper.com.br;
location / {
proxy_pass http://localhost:4000;
}
}
It's working completely fine but on the first request to the browser, shows this nginx screen. Looking my proxy configuration, does anyone know what i'm did wrong?
I kind solved this. I had to put these same options related to proxy on the other server config.

nginx settings are correct but fails to proxy: logs show zero error/activity

I have a domain that would hit my nginx proxy to be routed to their nodejs hosted site locally on a different port. About a month ago it stopped working:
DNS A records are fine and forward to correct IP
Website works if I go to ip address with correct port(3100)
Hell, it even works if I type domain.com:3100.
It's an Ec2 instance and port is open to all IP addresses
Here are the config file in the sites-enabled/site-available folder:
server {
listen 80;
server_name www.cpcarpet.com cpcarpet.com;
access_log /var/log/nginx/cpcarpetaccess.log;
error_log /var/log/nginx/cpcarpeterror.error.log debug;
location / {
proxy_pass http://localhost:3100/;
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've restarted the nginx service quite a bit and updated the package but nothing seems to work. Any ideas?
So to clarify what does work:
IP address:3100 works! Ok!
cpcarpet.com:3100 works!(So A records are set correctly) Works! Ok!
www.cpcarpet.com or cpcarpet.com? Does not work! Log files show no access/errors either.
Try this. Hope this helps you.
server {
listen 80;
server_name cpcarpet.com;
location / {
proxy_pass http://localhost:3100;
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;
}
}

Resources