nginx run npm with non-default port? - nginx

I have my angular app running in the root url, port 80, and I want to access the api running at port 8090. But when I try to change the port nginx listens to 8090 it says that I have a conflict (since npm is running it at 8090). So I switched it to 8100 instead. But when I try to hit that port it doesn't connect. My goal is to be able to go to http://174.131.183.112:8100 for my api.
server {
listen 8100;
server_name api._;
location / {
proxy_pass http://174.131.183.112:8090;
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;
}
}
Note: the weird thing is that if I don't have anything else running in nginx, then it still uses default port 80 to connect to my api, as if the 8100 wasn't there at all.

I realized that I setup ufw to block all ports. So I had to sudo ufw allow 8100 to open it and now it works.

Related

after installing Certbot (nginx) my domain is showing default Amazon Linux 2 page

I have successfully installed certbot on amazon linux 2 and my domain has padlock but it is not showing the node app which was hosted on my domain. now it is showing default amazon linux 2 page. before installing certbot my domain was showing the currect app. I still can access the app through the IP address and Port number.
I found the answer the problem was /etc/nginx/nginx.conf file wasn't configured for 443 port. it was redirecting to default app for the 443 ssl port. after adding the following code in server part of this file it resolved the issue.
location / {
proxy_pass http://localhost:3000; #chage port according to your app
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;
}

Despite hosting on nginx works fine in local web, it does not work with external ip

I have configured .net and nginx on ubuntu and it works in local web perfectly. I have static external ip, I have configured port forwarding on my router (I had done it for postgresql and it works fine from external web so I think I have done it properly) When it comes to nginx and when i type my ip f.e: xx.xx.x.xx:80 in url on computer in another web site is unreachable.
I have opened ports in firewall on linux:
sudo apt-get install ufw
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Here is my nginx config:
server {
listen 80;
server_tokens off;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I hope, I find solution but still I don't know why it works this way. I have changed listen port to 9000 or any different instead 80 in nginx config and in my router forwarding. Now everything works fine, why port 80 does not work?

configure nginx for MEAN stack

I heard that MEAN stack would be beneficial if it has nginx at front for some reasons and am following instructions from some people already done it. I installed MEAN stack via Bitnami and AWS and am trying to setting nginx configuration. I am modifying file /usr/share/nginx/default which contains this code.
server {
listen 80;
server_name example.com www.example.com;
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;
}
}
My question is that should I have to put my address instead of 127.0.0.1?
and should I have to keep 3000 and change my AWS port setting? Thanks in advance!
127.0.0.1 is a loopback ip address of the server, so the answer is no, you have to keep that ip address.
Port 3000 is an application port,that mean your application is listening on that port. Regularly, you can check port number that is in app.js or server.js files. You can change that port belong to port that you have set your application's port is listening. Sorry for my poor English.

Websockets on ElasticBeanstalk giving 404

I'm trying to deploy a websocket server to Elastic Beanstalk.
I have a Docker container that contains both nginx and a jar server, with nginx just doing forwarding. The nginx.conf is like this:
listen 80;
location /ws/ { # <-- this part only works locally
proxy_pass http://127.0.0.1:8090/; # jar handles websockets on port 8090
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / { # <-- this part works locally and on ElasticBeanstalk
proxy_pass http://127.0.0.1:8080/; # jar handles http requests on port 8080
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
I can run this docker locally and everything works fine - http requests are served, and I can connect websockets using ws://localhost:80/ws/ However, when I deploy to Elastic Beanstalk, http requests are still ok, but trying to connect websockets on ws://myjunk.elasticbeanstalk.com:80/ws/ gives a 404 error. Do I need something else to allow websockets on Elastic Beanstalk?
Ok, got it working. I needed the ElasticBeanstalk load balancer to use TCP instead of HTTP.
To do this from the AWS console (as it's laid out on 5/16/2015), go to your ElasticBeanstalk environment, choose "Configuration" on the left menu, under "Network Tier" there's a "Load Balancing" pane. Click its cog wheel, then you can change the load balancer protocol from http to tcp.

does nginx have to listen on port 80?

I have a node app that uses websockets which is working on local host but not in production. In production, the messages being posted aren't appearing in the client. Since it's using socket.io, I'm assuming this is a problem with the ports. In production, I'm using nginx with this as the following config. Nginx is listening on port 80 but I have the port for the application at localhost:3000. Every nginx config I've ever seen has it listening on port 80, and I've heard problems will result if I set localhost below 1000, yet I believe the socket.io is not working because these ports are not the same. Can you suggest how to fix this problem?
/etc/nginx/conf.d/example.com.conf
server {
listen 80;
server_name mydomain.com;
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;
}
}

Resources