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.
Related
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
I am using Express for serving static files and dynamic URLs on my nodejs app. I am generating a URL based on the :id in Mongodb and then on NGINX I am using Nodejs reverse proxy to serve this path to the user but it doesn't work whatever I try. It always says "CANNOT GET.."
I am running NGINX 1.14.2, Node 8.14.0. I have tried NGINX rewrite directive and various wild cards ( ~, ~^, ., etc.) but none of them have worked. I have included the current express code and NGINX config below. Any help is hugely appreciated
Express
router.get('/dynamic-uri/:fooId', function (req, res) {
res.render('index');
});
The resultant URL with :fooId is
https://example.com/myNodeApp/dynamic-uri/5c35e51228122504b57126d7
NGINX Config
location /myNodeApp/dynamic-uri {
proxy_pass http://x.x.x.x:3000;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
}
Of course the :fooId doesn't exist as a static path and to serve static files i have the following block which works fine
location ~* /myNodeApp/(static|img|media|app|css|js) {
proxy_pass http://x.x.x.x:3000;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
}
I will make it short without introductions ..
I'm having a serious issues with NGINX configuration (on google cloud) to make 2 nodejs apps working on the same domain with different PORTS
let's say app1 is working on port 3002, app2 working on port 3003
app1
location / {
root /home/bitnami/project_name;
proxy_pass http://127.0.0.1:3002;
proxy_http_version 1.1;
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 Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
}
app2
location /app2 {
root /home/bitnami/project_name;
proxy_pass http://127.0.0.1:3003;
proxy_http_version 1.1;
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 Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
}
when I surf www.example.com/app2, I get 404 page
I know some of u will say that this Q has been asked before, believe me I've tried all possible solutions on stackoverflow .. non has worked with me
Note: app1 location it has to be the main domain so (/) the main domain URL without path
I believe your code does not use relative paths, thats why you are getting this error, add this line:
rewrite ^/app2(.*) /$1 break;
and no root required for proxy pass, your new code shall look like this:
location /app2 {
#root /home/bitnami/project_name;
proxy_pass http://127.0.0.1:3003;
#proxy_http_version 1.1;
#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 Host $host;
#proxy_set_header X-NginX-Proxy true;
#proxy_redirect off;
rewrite ^/app2(.*) /$1 break;
}
The first location block captures requests for all requests of your domain, leaving the second block never used. Put the second block before the first one and it should work.
it's very short question, but i'm overwhelmed. I need nodejs app run under domain.com/nodeapp/.
The problem is - it works correct if i write domain name like: domain.name/nodeapp/ so when i'm go to domain.name/nodeapp - corrupted version loads.
I need nginx to redirect correctly to location with /nodeapp/
Now i'm using next config:
location /nodeapp {
proxy_pass http://localhost:20100;
rewrite ^/nodeapp/?(.*)$ /$1 break;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
How can i do it correct? Thanks!
This will do
location /nodeapp {
proxy_pass http://localhost:20100;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
To remove the use of ports on several of the applications running on this server, I've been using nginx's proxy_pass to do this. However, for some reason the actual url is being passed to the application. Is there a way so that it thinks /panel is really just /?
location /panel {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8082/;
}
You need to add the trailing slash
location /panel/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8082/;
}