Is it possible to use nginx proxy_pass without defining any location block?
Just send all incoming requests to nginx proxy to ingress controller.
According to Nginx documentation the only possible way to define proxy_pass directive is location context:
Context: location, if in location, limit_except
Related
i tried to forward traffic from server 192.168.243.71 to domain that show in command "oc get routes" / "kubectl get ingress", but its not as simple as that. The fact is my Nginx Reverse Proxy in server 192.168.243.x will forward the request to the IP Address of loadbalancer instead of the real domain that i wrote in nginx.conf
the result
I was expecting it will show the same result when I access the domain via web browser that show in "oc get routes" or "kubectl get ingress"
Solved by adding set $backend mydomainname.com in server block and add dns resolver resolver 192.168.45.213; proxy_pass http://$backend; server in location block.
Result
You can actually add the set $backend mydomainname.com on the server block, and also you need to add dns resolver resolver 192.168.45.213; proxy_pass http://$backend; server in the location of block
nginx(ng1): 172.168.240.5
Gitlab includ nginx (ng2): 172.168.240.55
ng1 config
listen 81;
server_name ng1;
location /gitlab/ {
proxy_pass 172.168.240.55/
}
how can I keep port and url without updating ng2. // only modify ng1
url gitlab lost
it's login(POST) http://ng1:81/gitlab/users/sign_in
but it's show http://ng1:81/users/sign_in instead of http://ng1:81/gitlab/users/sign_in
it seems to be rewrite by ng2
url gitlab and port lost
click one file in http://ng1:81/gitlab/root/pg/
but it's http://ng1/root/pg/index.html instead of http://ng1:81/gitlab/root/pg/index.html
need nginx reverse proxy
/servername/port/ for dynamic servername and port
I find resolve (dns server + nginx)
Using nginx regex location matching to dynamically map URI's to different ports for multiple reverse proxies
I'd like to reverse proxy my application under server.com/myapp/homem where server.com/myapp is the proxied address and /home is an URL handled by my app.
What is the best / recommended solution to do that so that the app will generate proper paths<img src="/myapp/static/...">
Which of the two following approaches I should take:
1. X-Forwarded-Path: I proxy GET Path=/home and add an X-Forwarded-Path: /myapp
2. Base_url set in config: I proxy GET Path=/myapp/home and set base_url = server.com/myapp
The nginx rewrite directive can handle what you are looking for
You server block should look similar to the following snippet
server {
listen 80;
rewrite ^/myapp/(.*)$ /$1 last;
location /home {
proxy_set_header X-Forwarded-Path myapp;
proxy_pass http://1.2.3.4;
}
}
Take a look at either of the following for more information
https://www.nginx.com/blog/creating-nginx-rewrite-rules/
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html
I have a nginx deployment in k8s cluster which proxies my api/ calls like this:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location /api {
proxy_pass http://backend-dev/api;
}
}
This works most of the time, however sometimes when api pods aren't ready, nginx fails with error:
nginx: [emerg] host not found in upstream "backend-dev" in /etc/nginx/conf.d/default.conf:12
After couple of hours exploring internets, I found the article which pretty much the same issue. I've tried this:
location /api {
set $upstreamName backend-dev;
proxy_pass http://$upstreamName/api;
}
Now nginx returns 502.
And this:
location /api {
resolver 10.0.0.10 valid=10s;
set $upstreamName backend-dev;
proxy_pass http://$upstreamName/api;
}
Nginx returns 503.
What's the correct way to fix it on k8s?
If your API pods are not ready, Nginx wouldn't be able to route traffic to them.
From Kubernetes documentation:
The kubelet uses readiness probes to know when a Container is ready to start accepting traffic. A Pod is considered ready when all of its Containers are ready. One use of this signal is to control which Pods are used as backends for Services. When a Pod is not ready, it is removed from Service load balancers.
If you are not using liveness or readiness probes, then your pod will be marked as "ready" even if your application running inside the container has not finished it's startup process and is ready to accept traffic.
The relevant section regarding Pods and DNS records can be found here
Because A records are not created for Pod names, hostname is required for the Pod’s A record to be created. A Pod with no hostname but with subdomain will only create the A record for the headless service (default-subdomain.my-namespace.svc.cluster-domain.example), pointing to the Pod’s IP address. Also, Pod needs to become ready in order to have a record unless publishNotReadyAddresses=True is set on the Service.
UPDATE: I would suggest using NGINX as an ingress controller.
When you use NGINX as an ingress controller, the NGINX service starts successfully and whenever an ingress rule is deployed, the NGINX configuration is reloaded on the fly.
This will help you avoid NGINX pod restarts.
Is there an equivalent of apache's ProxyRemote directive for NginX?
So the scenario is I am behind a corporate proxy and I want to do proxy passes for various services with NginX. I would do it in Apache with the following:
ProxyPass /localStackOverflow/ https://stackoverflow.com/
ProxyPassReverse /localStackOverflow/ https://stackoverflow.com/
ProxyRemote https://stackoverflow.com/ http://(my corporate proxy IP)
I know I need the proxy_pass directive in NginX but can't find what I would use for the ProxyRemote.
Thanks
Not sure how #tacos response can work - possibly something I'm missing but the only way I could sort of get this to work was by rewriting the url and passing on to the corporate proxy. This is shown below:
http {
server {
listen 80;
location / {
rewrite ^(.*)$ "http://www.externalsite.com$1" break;
proxy_pass http://corporate-proxy.mycorp.com:8080;
}
}
}
This works, but does rewrite the url, not sure if this is important to the original use-case..
The servers you proxy behind an Nginx front-end web server are referred to as upstream servers. You will want to refer to the documentation for the HttpUpstreamModule. It's very similair to what you are familiar with. If you don't need load-balancing, you just setup the one upstream server in the configuration and it will serve your purpose.