Nginx Proxy On Custom Port - node.js

I have a node process listening on port 11180, and would like to redirect all request from https:example.com:11179 to it. How can I accomplish this with nginx ?
I cannot use port 443, because it is forwarding to a different process. However I do have a certificate for the domain example.com
I have tried using this configuration
server {
listen 11179 ssl
location / {
proxy_pass http://127.0.0.1:11180
...
}
}
but the site just keeps loading, however the same configuration works if i listen on port 443
server {
listen 443 ssl
location / {
proxy_pass http://127.0.0.1:11180
...
}
}
Thanks a bunch for your help

Turns out it was a firewall problem :P

Related

Ubuntu 20 with NGINX add subdomain for existing IP

I have a small app written with NodeJS and it is hosted in Google Cloud. I reserved a IP and I can access the front of app with IP.
The problem is, I have an admin panel witch it is a different Node instance. This has his own port and I want to access it via url, like: http://admin.11.111.11.11
I've using NGINX with Ubuntu 20.4
Config for admin it looks like:
server {
listen 80;
listen [::]:80;
#server_name admin.11.111.11.111/ www.admin.11.111.11.111/;
location / {
#proxy_pass http://127.0.0.1:2222;
}
}
and for front:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name mydomain.com www.mydomain.com;
location / {
proxy_pass http://127.0.0.1:1111;
}
}
At this moment I can't transfer the domain. I must wait client to finish writing his content. The mydomain.com use an old CMS so we must wait to finish to transfer the content, so the new app it is accessible just through new IP.
Thank you for any hint!
This has his own port and I want to access it via url, like: http://admin.11.111.11.11
No, this isn't possible admin.11.111.11.11 is not a valid hostname. You can't mix hostnames and IP addresses as the host like that. This whole premise is flawed... this isn't an Nginx problem.

Nginx nodejs problems

I am trying to use nginx to direct a website hosted on port 8080 to domain exemple1.com and another one on port 8081 that i want to redirect to domain exemple2.com.
On the file /etc/nginx/sites-available/default i puted this code:
location ~/example1/ {
proxy_pass http://example1.com;
}
location ~/example2/ {
proxy_pass http://example2.com;
}
but i couldn make it work . I am running 2 nodejs servers on the ports i talked about (port 8080 and 8081).
What i am doing wrong and how to "fix "
it?
Because the downstream app server running on different ports(listen) than coming in, you need to specify ports in proxy_pass. So I think
listen 8080;
location ~/example1/ {
proxy_pass http://example1.com:8080;
}
location ~/example2/ {
proxy_pass http://example2.com:8081;
}

Cannot Connect subdomain of route 53 to ec2 node js app

But It's working fine with public IP as below
And I have created a subdomain with route 53 and then assigned A record with instance public IP
But when I ping the domain and IP it's getting request time out and all packets were lost. My application is node express app.So please it's a huge favor if anyone can solve this issue.
From your screenshot, I found that you're using Nginx as a Reverse proxy. So it might be because of your Nginx config
example your Nginx config may look like this,
server {
listen 80;
server_name 192.168.1.21;
...
}
you've to update it to:
server {
listen 80;
server_name subdomain.domain.com;
...
}

ExpressJS Server - respond to host header with shared port

Lets say I have corporatewebsite.com listening on port 80. Which is an appache / WordPress site.
I have a node application that I'd like to respond to sub.corporatewebsite.com
The node application is running Express currently. I can get it to listen to a separate port at the moment, but my service won't start if it's pointed to port 80 since it's already in use.
How can I have both apache and node listening to port 80, but having node responding to the subdomain?
You could use a reverse proxy like Nginx to route your subdomains.
Here is an example of nginx configuration, you might probaly have to complete according to your project and server :
server {
listen 80;
server_name corporatewebsite.com;
location / {
[ ... some parameters ... ]
include proxy_params; // Import global configuration for your routes
proxy_pass http://localhost:1234/; // One of your server that listens to 1234
}
}
server {
listen 80;
server_name sub.corporatewebsite.com;
location / {
[ ... some parameters ... ]
include proxy_params;
proxy_pass http://localhost:4567/; // The other server that listens to 4567
}
}
You have to configure, for example, apache2 listening to port 1234 while nodejs is listening to port 4567.
If you do like this, a good practice is to block direct access from the outside to your ports 1234 and 4567 (using iptables for example).
I think this post could be useful to you : Node.js + Nginx - What now?

Add subdomain for port that listen node.js

Hi guys i have a problem. I work with php and node, php works with nginx listening port 80 and node works with the port 3000. I want add a subdomain that listen port 3000 a like media.mydomain.com but i could not. I tried with my website register domain and nothing happened and then with nginx in virtual host but show in console error because this port it is using.
nginx-php=mydomain.com
node=mydomain.com:3000 (tried add subdomain "media.fotogena.co")
virtual host:
server {
server_name media.mydomain.com;
listen mydomain.com:3000;
#i don't know that do!
}#show error port is being used
and had seen something like upstream but this assign port 80 to port 3000 but don't is the that me need
If i understand what you want to do, you want a subdomain to use instead of the port 3000, for the subdomain to work you need it to listen on port 80, and proxy what ever comes to port 3000.
server {
server_name sub.example.com;
listen 80;
location / {
proxy_pass http://localhost:3000;
}
}

Resources