need help on nginx configuration for nodejs api - node.js

my node api starts on port 1337 and works fine. if I browse localhost:1337 my api return nothing and if I browse localhost:1337/products my api actually works fine and return my products list as Json.
now service nginx installed and configured well to reverse-proxy of localhost:1337 to localhost
so after opening localhost it somehow works and says nothing as before but if I try browsing localhost/products again says nothing
and don't care about products.

I just have found the issue.
in nginx default configuration removed everything in section location /api/ just copy proxy_pass http://localhost:1337/; lonely. and it works correctly.

Related

Nginx proxy with node. weird rewrites when ran on port 80

location /api{
rewrite /api(.*) $1 break;
proxy_pass http://api;
}
so I have a node server running inside a container and using Nginx as a proxy it works fine if the container listens on any other port than 80. But when on 80 it only rewrites/reroutes two routs /api/v1/vendors and /api/v1/products to /v1/vendors/ and /v1/products/. but all other routes work fine. and the issue is fixed when I append a trailing / to /api/v1/vendors and /api/v1/products. can anyone explain why this might be happening? and it also fixes itself when I change the name of the routes even taking the s off works
you can try this behavior on https://api.oroshops.com/api/v1/vendors and https://api.oroshops.com/api/v1/vendors/
you can try this behavior on https://api.oroshops.com/api/v1/users and https://api.oroshops.com/api/v1/users/

How to configure weinre behind Nginx proxy?

I have the latest weinre installed (2.0.0-pre-I0Z7U9OV). I can start it, all is working fine, but I need to run it behind a Nginx Proxy to be able to use a trusted SSL Certificate. So what I tried is the following:
upstream weinre {
server 127.0.0.1:8080;
}
server {
...
location /weinre/ {
proxy_pass http://weinre/;
proxy_set_header Host $host;
}
}
The site is opening, all fine, but when adding the target script to my mobile page, I can't see it appear in the targets list. So I started to dig into it and found the follwing in the Chrome console:
POST https://domain.net/ws/target 404 (Not Found)
Why is it POSTing to ws/target and not weinre/ws/target? Since everything else is working under the weinre sublocation.
Is it even possible to run weinre under such setup?
Not quite sure what's going on there; what is the URL of the of the target script you are embedding in your page? It's possible to override the URL of the weinre server, instead of having it calculated from the target script, by setting the global window.WeinreServerURL, as you can see in the Target.coffee file. You can see how the server URL is used to get the URL to the "socket" URL here.

502 Gateway Error on AWS - API

I am creating a test web app and have deployed it to AWS Ubuntu server using nginx..
I am getting a 502 Bad Gateway error when it tries to reach my API..
I am new to this and have started node.js and all seems to working fine except when I want to perform an API call to mongodb to read or write information. it is working fine locally so I am at a loss....
GET http://ec2-54-72-145-112.eu-west-1.compute.amazonaws.com/api/rest/golf 502 (Bad Gateway)
this is nginx server config
location /xxxxxxxxxxxxxxx{
alias /home/ubuntu/xxxxxxxxxxxxxx/site/public;
}
location /api/ {
proxy_pass http://127.0.x.1:8180/api/;
}
..
I know I may not be giving enough info but hopefully someone has an idea..
Thanks!
The nginx error message HTTP 502 indicates the nginx is working fine but cannot reach your specified proxy. So I'd suggest you to check whether the port and binding IP are correct.
You can check which ports are bound by which application using this command on your Ubuntu machine:
netstat -tulpen
You should see a line with the column "Local Address" and in your case the value 127.0.x.1:8180. If it's not there try to figure out which port is bound by your node application and reconfigure the nginx to use that port.

403 Forbidden after successfully installing Ghost

I have been spending days figuring out how to install the viral Ghost platform, and experienced numerous errors. Luckily, I have managed to install it - Ghost gives me a positive Ghost is running... message in SSH after I've done npm start --production. However, when I browse to my website - http://nick-s.se - Apache displays its default page and when I go to the ghost login area - /ghost, the site returns a 403 Forbidden.
P.S. I have specifically installed Ghost on a different port than the one Apache is running on. I don't know what's going on...
Update - I have found out that I can access my Ghost installation by adding the port number 2368 which I've configured in the config.js. Now, however my problem is - how can I run Ghost without using such ports?...
tell your browser you want to connect to the port Ghost is running on: http://nick-s.se:2368
So a few things, based on visiting:
1) It seems Apache isn't proxying the request onward to Ghost. Are you sure that you've configured it properly?
2) It also looks like Apache doesn't have access to the directory that you set as root. This shouldn't be necessary anyway if proxying is set up correctly, but could become an issue later if you wanted to use apache to serve things like the static assets.
If you are open to nginx instead of Apache, I have written a how to on this: link. You can skip the section on configuring Nginx. Otherwise, still might be useful if you figure out the conversion of rules from Nginx to Apache.
If you don't have any other sites running on your VPS you can just turn apache off and not have to deal with apache proxying the request to port 2368 and have Ghost run on port 80. If your VPS is running CentOS you can check out this how to on disabling apache and running Ghost on port 80.

Can't get to my nodejs server through web browser

Alright, so I setup a node.js server quite a while ago on a AWS EC2 micro server. I was completely new to it and followed various tutorials to get it up and running. It used nginx as a reverse proxy (I believe) and the server was listening on port 8124.
Now, the instance got restarted and I can't for the life of me get access to my server back. I can ssh to it. I can start the server. I can send POST/PUT requests to it through my local command line, but my web browser gives me the 404 nginx page.
This is driving me up the wall - where in the browser/nginx/nodejs chain are things breaking down?
Please help - I'm horribly new at this at it must be a single line somewhere that's broken. I just don't know enough to find it.
My /etc/nginx/sites-enables/default file simply contains
location / {
proxy_pass http://127.0.0.1:8124/;
}
Okay I figured it out. I had to go directly into /etc/nginx/nginx.conf and in the server that was there
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
I added the line
proxy_pass http://127.0.0.1:8124/;
Oh thank god. That was going to kill me.

Resources