I have a task to connect a jitsi server with my existing domain. The jitsi server should be running in a subpath like https://dev.example.com/video.
I have installed jitsi in aws with hostname https://dev.example.com.
For this to work I have to set up an nginx block that will remove /video while sending a request to the jitsi server and add /video on the responses.
The plan was to add an upstream in my nginx as follows.
upstream jitsi {
server 10.10.10.20:443;
}
location /video/ {
rewrite ^/video/(.*) /$1 break;
proxy_pass https://jitsi/$uri$is_args$args;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect https://dev.example.com/ https://dev.example.com/video/;
}
The rewrite will strip away the /video and the rest is supposed to add it on the response. But when loading the page, browser is showing 404 for some of the internal links.
eg:
https://dev.example.com/libs/do_external_connect.min.js?v=1
[HTTP/1.1 404 Not Found 124ms]
https://dev.example.com/libs/lib-jitsi-meet.min.js?v=4466
[HTTP/1.1 404 Not Found 123ms]
https://dev.example.com/libs/app.bundle.min.js?v=4466
[HTTP/1.1 404 Not Found 123ms]
https://dev.example.com/static/pwa/registrator.js
I could clearly see that the last part which is supposed to add /video into the URL is not working correctly.
What am I doing wrong here?
Thanks in advance
Related
I have an nginx running on a docker container, which serves a web client.
I want to proxy requests from the client, so that the nginx will pass the POST requests to the server, since the actual destination endpoint is not accessible to the client.
This is the location directive:
location /zipkin {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header Host $host;
proxy_pass http://my-ip:9411/;
}
The client makes requests to http://localhost:8080/zipkin/api/v2/span, which I want the nginx to pass (without redirection) to http://my-ip:9411/api/v2/span.
What happens in practice is that I get a 301 response (to http://localhost:8080/api/v2/span), and the POST is never sent to the destination.
Edit: another try that returns 404 -
location /zipkin/ {
rewrite ^/zipkin/(.*) /$1 break;
proxy_pass http://my-ip:9411$uri; # tried 9411;, 9411/, 9411$uri, 9411$uri/
}
Here $uri is /api/v2/span.
The solution in the end was:
location ~ ^/zipkin(/?)(.*) {
proxy_pass http://my-ip:9411/$2;
}
One of my tries was ^/zipkin(.*) but it evidently didn't work.
Probably the / after the /zipkin is problematic, so (/?) removes it,
And that leaves the (.*) the clean part of the url which needs to be attached to the proxy_passed url.
I had a proxy server which redirects communications to some api on customer side via https. When I use configuration with set upstream variable (proxy_pass $upstream_endpoint$request_uri;), the DNS resolving for this domain (dynamic changing IP adress) is working well but I get response 403 unauthorized.
When I use configuration without upstream (proxy_pass https://api-test.example.com/api/), point directly to customer domain it works well, I am getting response 200 but DNS resolver is not working anymore..
Nginx config:
location /api-test.example.com/api/ {
resolver 10.100.10.1 valid=5s;
set $upstream_endpoint https://api-test.example.com;
proxy_pass $upstream_endpoint$request_uri;
#proxy_pass https://api-test.example.com/api/;
proxy_ssl_name api-test.example.com;
proxy_ssl_server_name on;
proxy_set_header Host api-test.example.com;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
By adding a URI to the proxy_pass statement, the requested URI is rewritten before passing it upstream. See this docuement for details.
So the URI /api-test.example.com/api/foo is rewritten to /api/foo.
You can achieve the same behaviour with a rewrite...break statement. See this document for details.
location /api-test.example.com/api/ {
rewrite ^/api-test.example.com(.*)$ $1 break;
set $upstream_endpoint https://api-test.example.com;
proxy_pass $upstream_endpoint;
...
}
I am trying to call a GET api with a parameter which has space in it:
https://abc.xyz/search/web/buildings/search/v2/city/new%20york
The endpoint hits load balancer (nginx) which redirects the request to a suitable machine.
In the response, I get 505 HTTP Version Not Supported error. But when I make the same request to the load balancer using HTTP (using internal IP), it returns the response successfully.
Here are the relevant access logs of both cases:
access log of nginx when called via http
"GET /search/web/buildings/search/v2/city/r%20c HTTP/1.1" S=200 487 T=0.005 R=- 10.140.15.199
access log of the machine when called via http
"GET /search/search/web/buildings/search/v2/city/r%20c HTTP/1.0" 200 36
The above request works fine. but when we request through https, the request in machine comes differently (it should have been d%20a instead of d a)
access log of nginx when called via https
"GET /search/web/buildings/search/v2/city/d%20a HTTP/1.1" S=505 168 T=0.001 R=- 35.200.191.89
access log of the machine when called via https
"GET /search/search/web/buildings/search/v2/city/d a HTTP/1.0" 505 -
Here is the relevant nginx configuration:
upstream searchtomcat {
least_conn;
server search-1:8080;
server search-2:8080;
}
server {
#listen 443 ssl http2;
listen 443;
client_max_body_size 100M;
...
location ~* ^/search/(.*)$ {
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;
proxy_pass http://searchtomcat/search/search/$1;
proxy_read_timeout 900;
}
}
There is nothing in error.log.
What could be the possible reason because of which the machine is getting request in a different manner?
The whole issue.is happening because of the space that is coming in your URL that is being sent over to tomcat. Because of it, a is being interpreted as the HTTP version code and not HTTP/1.0. Solving the extra space issue will solve the problem.
Using rewrite in location{} block should solve the problem.
location /search/ {
rewrite ^/search(/.*) /search/search$1 break;
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;
proxy_pass http://searchtomcat;
proxy_read_timeout 900;
}
Also, you have different configurations for http and https servers, have a look at the http one. That one seems to be correct.
I was getting 505s when trying to set up port forwarding on nginx.
For me the solution was to add this line to my location block containing the the proxy_pass directive:
proxy_http_version 1.1;
Closest to the doco I can find on the topic is here
I have a problem with nginx to download an excel file using the Http POST method. In fact I am getting a Status Code: 405 Not Allowed.
here is my configuration
upstream backend{
server localhost:9090;
server localhost:9091;
server localhost:9092;
server localhost:9093;
}
server {
listen 8887;
server_name localhost;
location / {
proxy_pass http://backend;
proxy_next_upstream error timeout http_404;
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;
}
}
how can I solve this problem.
Thank you in advance.
Nginx responds with an HTTP 405 for POST requests that try to access a static asset.
From the Nginx release docs from a few years back:
*) Feature: now Nginx returns the 405 status code for POST method
requesting a static file only if the file exists.
A way to go around it would be to add this line, which changes the response code and sends you to the requested URI:
error_page 405 =200 $uri;
You can find other solutions here:
http://invalidlogic.com/2011/04/12/serving-static-content-via-post-from-nginx/
I hope this helps.
I'm trying to run a squid server behind nginx.
I configured nginx like this:
server {
listen 8080;
location / {
proxy_pass http://localhost:3128;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Then I set my http network proxy to:
my-nginx-server-address:8080
So when I try to view the Google homepage, the nginx will get the request:
Get http://www.google.com/ HTTP/1.1
However when nginx pass the request to squid it will change the request_uri to
/
So squid won't work.
Is there any way I can set the request_uri back to http://www.google.com then pass it to squid? Or any other ways I can run squid behind nginx?
Try proxy_set_header Request-URI $request_uri;
In reply to your comment, you may also prefer to add:
upstream _squid {
server localhost:3128;
}
server {
...
proxy_pass http://_squid/$host$uri;
}