nginx and proxy_redirect partially working? - javascript

I'm having a lot of trouble trying to reverse proxy a .NET application (specifically sharepoint)
The sharepoint application lives at 192.168.5.8
nginx lives at 192.168.2.115 and has another IP at 192.168.5.200
I am using nginx to proxy several applications using the url to distinguish each app
My problem is with "/vmlab/" and not "/rdp/"
sites-available/default:
location ^~ /vmlab {
proxy_pass http://192.168.5.8/;
proxy_redirect http://192.168.2.115/ http://192.168.2.115/vmlab/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
proxy_set_header Authorization "Basic {base64 string}";
}
location /rdp/ {
proxy_pass http://192.168.2.115:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffering off;
#proxy_buffers 32 4k;
}
So when I hit http://192.168.2.115/vmlab the back-end request goes to http://192.168.5.8 which is great, except that the web application automatically sends a location redirect Location: http://192.168.2.115/default.aspx, therefore I added the proxy_redirect which seems to partially work.
My problem is that even though some requests like http://192.168.2.115/vmlab/default.aspx are being now being proxied to http://192.168.5.8/default.aspx (but show as http://192.168.2.115/vmlab/default.aspx) with the proxy_redirect, others that show up in the client browser (such as javascripts and stylesheets) still show like the following http://192.168.2.115/_layouts/... which is missing the required "/vmlab/" URI and therefore don't exist.
Is this a problem with my configuration and the proxy, or by design with absolute paths in stylesheets and javascript code?

Related

Graphql web socket connection failed over production

I Have tried every possible Nginx config but it's showing connection failed every time.
config file:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:1337;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
}
location /graphql {
proxy_pass https://bakbakgraphql.com/graphql;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
Error:

deploying Angular + Node Express with Nginx, return blank page

I'm trying to deploy my angular application on my EC2. I already have a Different app running on port 3000. now i'm trying to deploy my angular app on port 3030. but when i access it via the IP:3030 it works fine, but after configuring it with nginx it returns black page and with some 404 error on the Network tab.
server {
listen 443 ssl;
server_name <ABC.DOMAIN.COM>;
ssl_certificate /etc/letsencrypt/live/<ABC.DOMAIN.COM>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<ABC.DOMAIN.COM>/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
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 $http_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 http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
location /goalmate{
rewrite /goalmate/(.*)$ /$1 break;
proxy_pass http://localhost:3030/;
}
}
}
server {
listen 80;
server_name <ABC.DOMAIN.COM>;
return 301 https://$host$request_uri;
}
Error Showing in the Networktab
can someone help me.?
should'nt the requeston the networkTab show domain.com/goalmate/assets/ other than domain.com/assests

Hosting two websites in one domain using nginx

I have an angularjs website (with a nodejs server.js file that hosts it on port 8100). I use Nginx to reverse proxy into that port.
I would like users who come to a separate path (say www.example.com/location1) to go to a completely different website (a different AngularJS folder with a different server.js file).
The Node.js files run on my server. But the front end throws an injection error when I try to run the two websites. Is it even possible to do this?
FYI: When I run a single website on the server, it works... but it doesn't work when I run both.
Edit: both the websites work on my localhost perfectly.
My Nginx sites-available/default file
server {
...
location / {
proxy_pass http://127.0.0.1:8100;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /location1/ {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
My Server.js files (more or less the same for both files):
var express = require('express')
var app = express();
path = require('path');
app.use(express.static(path.join(__dirname,'pw')));
app.all('*',function(req,res,next){
res.sendFile('pw/index.html',{root:__dirname});
});
app.listen(8100); //This will be 8080 for the other server.js file (which has been renamed something else

NodeJS cannot upload file cause upstream prematurely closed connection

When created a website with nodejs. In this website I have a page that can upload image to server. I tested this on my computer it's work fine. After I deploy it to server it's not working. I read the log. I got two from both access and error log at the same time.
This is an error.log
upstream prematurely closed connection while reading response header from upstream , client: xx.xx.xx.xx, server: example.com, request: "POST /admin/place/thumbnanil/upload HTTP/1.1", upstream: "http://127.0.0.1:3002/admin/place/thumbnanil/upload", host: "example.com", referrer: "https://example.com/admin/place/detail"
This is an access.log
POST /admin/place/thumbnanil/upload HTTP/1.1" 502 583 "https://example.com/admin/place/detail"
This is my nginx virtual host
upstream example {
server 127.0.0.1:3002;
keepalive 8;
}
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
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 Host $host;
proxy_cache_bypass $http_upgrade;
proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 2048 8k;
}
}
I'm using ubuntu 14.04 on AWS EC2.
NodeJS v4.4.7
This is the url that I'm using for post : https://example.com/admin/place/thumbnanil/upload
Try this,
location / {
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_pass http://localhost:3002/;
proxy_read_timeout 90;
proxy_buffering off;
proxy_redirect http://localhost:3002/ https://example.com/;
}

Node.JS/socket.io and safari

I have a node.js software that use socket.io 1.3.0 lib for communication between client and server.
In my architecture the server is behind a proxy nginx.
I test the software with all last browser version.
Everything works except when i use Safari (last version).
I read that Safari uses an earlier version of the protocol WebSocket (hixie-76).
My question is: there is a way to change in socket.io the protocol version when i use Safari browser?
This is my nginx (1.7.12) configuration:
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
proxy_pass http://internalhost:8080/;
}
Thanks in advance.

Categories