Nginx - Reverse proxy all requests starting with a keyword - nginx

I want to redirect all requests starting with "mydomain/_dash" to "mydomain:8050/_dash" so that "mydomain/_dash-component-suites/" redirects to "mydomain:8050/_dash-component-suites/". I have added the following directive but it doesn't work. Plus, I also want to maintain the headers of each request.
location /_dash(.*)$ {
proxy_set_header Host $http_host;
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 X-Scheme $scheme;
client_max_body_size 0;
proxy_pass http://analytics:8050/_dash(*);
}

You need to use regular expressions:
location ~ /_dash(.*)$ {
proxy_set_header Host $http_host;
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 X-Scheme $scheme;
client_max_body_size 0;
proxy_pass http://analytics:8050/_dash$1;
}

Related

Reverse proxy errorr

I've reversed proxied icecast but the ips are not getting forwarded to the admin panel all i get is 172.20.0.1.
I would like the ips of the listeners to be send to the icecast admin panel which is being accessed by the server ip and port 8000.
The server is proxied by cloudflare would this make a difference?
This is the NGINX config incase i've done something wrong.
server {
listen 80;
listen [::]:80;
server_name example.net;
location / {
proxy_pass http://127.0.0.1:8000/stream;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
location /web {
proxy_pass http://127.0.0.1:8000/web;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}

Nginx forward requests to the new URL

How can i change url for site in Docker?
This conf work fine
location / {
proxy_pass http://127.0.0.1:3333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
but with this conf not work
location /newurl/ {
proxy_pass http://127.0.0.1:3333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Take 404 not found for scripts,css files.
Can anybody tell me about configuration nginx, please?
Thanks
i think you need to replace the /newurl/ with command
location /newurl/ {
rewrite ^/newurl/(.*)$ /$1 break;
...

Location wildcard for nginx block

Very new to nginx config, i'm trying to configure a location block to use a wildcard after "/dev/"
Example of what works below:
location /agent-d-ccp/dev/getcalltypelist/GEQ {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-apigw-api-id XXXX;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $backend XXXX;
proxy_pass $backend/dev/getcalltypelist/GEQ;
}
But I need a wildcard for anything after "/dev" because "getcalltypelist" will change and so will "GEQ"
location ~* ^/agent-d-ccp/dev/(.*) {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-apigw-api-id XXXX;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $backend XXXX;
proxy_pass $backend/dev/$is_args$args;
}
I've tried the above but just doesn't seem to work, does ^/agent-d-ccp/dev/(.*)
need to be "^/agent-d-ccp/dev/(.*)/(*.)" for example ?
Thank you to all who respond.
To share for anyone else having the same issue, see answer below:
location ~* ^/agent-d-ccp/(.*) {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-apigw-api-id XXXX;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $backend XXXXX;
proxy_pass $backend/$1$is_args$args;
}

alertmanager unsee behind nginx proxy

I'm trying to serve alertmanager and unsee from the same container.
In my testing:
I background alertmanager
I background unsee
I run /sbin/nginx
when I visit / I can see alertmanager
when I visit /unsee I get ERR_INVALID_RESPONSE
I can curl http://127.0.0.1:8080 and see that unsee is serving files
I have the below config in /etc/nginx/sites-enable
server {
listen 9093;
location / {
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_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:9094;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /unsee/ {
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_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
so the configuration should be like this ...
server {
listen 9093;
server_name alertmanager.*;
location / {
resolver 127.0.0.11 ipv6=off;
set $target http://container_hostname:9094;
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_pass $target;
}
}
server {
listen 9093;
server_name unsee.*;
location / {
resolver 127.0.0.11 ipv6=off;
set $target http://container_hostname: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_pass $target;
}
}

Deploy Udash demo app to NGINX

How can I deploy the Udash framework demo outside of SBT, and run it under NGINX?
I know it is lame, but I am able to run under NGINX with this line:
nohup sbt -Djline.terminal=jline.UnsupportedTerminal run &
and these location mappings:
location /notifications/ {
proxy_pass http://127.0.0.1:12345;
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;
}
location /atm/ {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /frontend/ {
proxy_pass http://127.0.0.1:12345;
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;
}
location / {
proxy_pass http://0.0.0.0:8080;
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;
}

Resources