I deploy a Mean app with nodejs and express.
I made a reverse proxy with nginx.
`
location /soc/ {
root /capza_app/back/;
index index.js;
# proxy_set_header X-Real-IP;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header AccesControl-Allow-Origin *;
proxy_pass http://ip:3000/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
`
I call my api in front here:
apiUrl = 'https://mydomain/soc/transaction/'
After all go in back in my index.js:
app.use('/soc/transaction', TransactionController);
My index send in my controller.
I have 404 error.
Without the reverse proxy, i have Mixed Content: The page at https as loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint http.
maybe routes problems but I don't know what i am do wrong.
Thanks
I try to change my route, chang my reverse proxy
Related
My website has the proxy server created using express nodejs with nginx. The problem I am having, and cant seem to figure out is that I want to forward all the original users details and not show any proxy server details to the final destination server.
Scheme:
User -> my website -> proxy server -> final server to retrieve the data.
Now, no matter what configs I change in nginx, seems like the final server always identifies my proxy server isp, geo etc and not the users isp. If I access the final server directly without the proxy, the final server will show users isp.
How do I make sure that the proxy server is not being detected as "original" requester to the final server?
Some code for better understanding:
Nginx proxy:
location / {
proxy_pass http://x.x.x.x.x;
include proxy.conf;
}
nginxconfig:
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
Requests inside the node (to call final server) made like this (just a sample):
app.post('/getStats', (req, res) => {
const url = request('url')
req.pipe(url).pipe(res)
})
I'm using Nginx with Nodejs backend. I use Nodejs for authenticating users and api calls. Currently I have the following in my Nginx configuration:
location /api {
proxy_pass http://localhost:5000/api;
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;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
However, this allows anyone to access /api directly. Is there a way to configure this so that users can't directly access /api?
Update
I tried adding:
allow 127.0.0.1; deny all; to the nginx config, however, this also blocks nginx from getting the resources. In other words, users can no longer login or get the resources from api.
I added a middle-ware to express and it always receives 127.0.0.1 (localhost) as the req.ip so I cannot do anything on nodejs side to prevent this because all requests are redirected from nginx.
I am very lost at the moment, so much so that I actually signed up because of my problem. So here we go: I am running a System with Plex and I am trying to get a node.js Backend with socket.io to work that is running behind Nginx.
The proxy pass for my HTML (I am using ejs to be precise, not sure if relevant) hosted via express works like a charm. But I get a 404 error when my website tries to connect to my backend via socket.io.
My Nginx directives as configured via Plex:
location = / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:50090;
}
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_pass http://127.0.0.1:50090/socket.io/;
}
My client connecting to the backend:
var socket = io.connect('https://subdomain.mydomain.com', {secure: true});
My Backend listening:
const app = express();
const http = require('http').createServer(app);
const io = require('socket.io').listen(http);
http.listen(50090, "127.0.0.1");
There is a lot about this on the internet, but it seems like I tried everything by now and nothing worked. Likely because I am very new to this.
i have a laravel app and i want all requests to domain.test/api to be proxied to nodeJs but only if it is an xhr request. meaning that if a user types in a browser domain.test/api i want to give him a 404 but if the request is made with ajax i want to give him the response.
the following configuration proxies all:
location ~* ^\/api(.*)$ {
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 300;
proxy_pass http://localhost:8081;
}
Is what i want to do possible using nginx? if so, please do suggest your solutions?
I have 2 server:
Server 1 is for loading balance with Nginx - https://server1.herokuapp.com/
Server 2 is for acting RESTful APIs. - https://server2.herokuapp.com/
Here my configuration of nginx.conf.erb at Server 1: https://gist.github.com/ntvinh11586/5b6fde3e804482aa400f3f7faca3d65f
When I try call https://server1.herokuapp.com/, instead of return data from https://server2.herokuapp.com/, I reach a 400 - Bad request. I don't know somewhere in my nginx.conf.erb wrong or I need implement nginx in server 2.
Try to research some resources but I found almost these tutorials configuring in localhost instead of specific hosts like heroku.
So what should I do to make my work successfully?
You need to configure your app as follows -
#upstream nodebeats {
# server server2.herokuapp.com;
# }
server {
listen <%= ENV['PORT'] %>;
server_name herokuapp.com;
root "/app/";
large_client_header_buffers 4 32k;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://localhost:<node-app-port>;
}
My two cents.
Comment out the upstream. Work with a single server server1.herokuapp.com, get it working with the above implementation, and then you can accomplish on adding the server2.hreokuapp.com to load balance.