I have to apps running in a vps, react app and nodejs api. and this is my nginx configuration
location /app {
proxy_pass http://myhost: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-Server $host;
}
location / {
root /var/www/frontend/;
index index.html;
}
the location for the frontend app is workin fine.
the problem is that i try to access the api endpoints i get error, the endpoint is not reached.
Example i try to access http://myhost/app/api/v1/user, i get this error:
Cannot GET /app/api/v1/consenting
Related
I'm running an Express server on port 5000 and a React app on 8080.
My idea was to just direct traffic based on location (uri), but I've been getting a duplicate location "/" error with this partial insert into the AWS Beanstalk ngnix config:
location / {
root /var/app/current/build/;
try_files $uri /index.html;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /socket-io {
proxy_pass http://127.0.0.1:5000/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
proxy_ssl_session_reuse off;
proxy_cache_bypass $http_upgrade;
}
This gets included in a standard ngnix.conf which looks roughly like this: https://gist.github.com/alextanhongpin/00da7f551969f052e57f3c4dcd9ac4b0
This is some combination of this answer and this other one since AWS documentation keeps changing.
On EC2, the file /etc/nginx/conf.d/elasticbeanstalk/00_application.conf is the file that appears to get appended on the main nginx.conf file with the line /etc/nginx/nginx.conf.
HOWEVER
The latest documentation says having .platform/nginx/conf.d/your_custom.conf in your working directory is the real nginx extension file.
I had to manually change 00_application.conf on EC2 in order for the duplicate error to go away, it appears this file stayed default even when redeploying with the custom config files, and that file happens to have a location / {}.
So I would recommend the container_command method or manually changing it for now.
I have a laravel website, where on my website there is a feature to get IP address for clients that open my website.
But when I use nginx for reverse proxy, on my website what is read is the Nginx server IP, not the client IP.
I already added :
proxy_set_header Host $ host;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
And this my nginx configuration :
upstream my.site {
server 192.168.1.5:30111;
server 192.168.1.4:30111;
server 192.168.1.3:30111 backup;
server 192.168.1.2:30111 backup;
}
server {
server_name my.site;
location / {
proxy_pass http://my.site;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Still not working.
Please help me.
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 have nodejs app (techkids.vn) that run on port 8080 and Django application running on port 8000 of the same server. Then I want to map the Django application on domain techkids.vn/djangoapp. This is my current configuration on Nginx (default.config), but its not work
Code:
location / {
proxy_pass http://127.0.0.1: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;
try_files $uri $uri/ =404;
}
location /djangoapp/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8000;
}
I run my node app on localhost:3000 and it is serving a default page for the route /. If I access http://localhost:3000 the default page is displayed accordingly. I have also running a Nginx server that is basically configured as followed:
server {
listen 80;
server_name localhost;
location /node_app {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
If I run http://localhost/node_app now, my node app throws an error saying that it cannot find route /node_app.
How can I configure either my node app or the nginx server in a way that I can access the app by calling http://localhost/node_app, yet the app itself thinks it is at /?
Update
If I add a / to http://127.0.0.1:3000 it is actually matching /node_app to the / route. But now every stylesheet for instance within the default page is now pointing to the wrong path.
After experimenting a bit around I finally got the configuration right to work exactly how I wanted the server to work:
server {
location /node_app/ {
proxy_pass http://localhost:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Lesson learned: Remember the slashes!