jupyterhub nginx reverse proxy - nginx

I'm trying to get a reverse proxy (nginx) to work with juypterhub. I want the service available at myurl.com/jhub/. I placed the following in the config:
location /jhub/ {
proxy_pass http://127.0.0.1:8000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
#WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
However, when I try the url after restarting the proxy jupyterhub is not available and I get a '404' Not Found error. I've tried every combination of ports and address with no luck. The same approach works just fine for RStudio server.... What am I missing?

Related

influxdb2 and nginx reverse proxy

I have installed influxdb2 from their website and setup nginx according to this amazing guide from digitalocean. I am trying to set a reverse proxy in order to query and post data to the db. I have my own URL and have set A records and a wildcard. I can access https:www.mydomain.com and mydomain.com .
problem 1.
when I run influxd I get the following error:
Error: listen tcp :8086: bind: address already in use
If I stop the service with sudo systemctl stop influxdb, I can then start the db. I cannot access it though...
problem 2.
the proxy is not working. Do you have any idea why?
My /etc/nginx/sites-enabled/mydomain.com.conf:
# reverse proxy
location /infuxdb {
proxy_pass http://127.0.0.1:8086;
proxy_set_header Host $host;
include nginxconfig.io/proxy.conf;
}
and the contents of /etc/nginx/nginxconfig.io/proxy.conf:
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
# Proxy SSL
proxy_ssl_server_name on;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Forwarded $proxy_add_forwarded;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Proxy timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;

Use nginx location blocks with Shinyproxy

I recently successfully deployed a ShinyProxy + app using SSL with nginx and certbot in the following manner:
Dockerize ShinyProxy + app and launch on port 127.0.0.1:5001.
Create Nginx config and proxy_pass to 127.0.0.1:5001.
Secure using certbot.
This is the successful nginx.conf location section:
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_redirect off;
proxy_read_timeout 90s;
proxy_pass http://127.0.0.1:5001;
}
This nicely redirects me to https://app.myweb.com/login as I have set up a CNAME. Important to note, {ShinyProxy} redirects to the login at the end automatically. On successful login the url redirects to https://app.myweb.com/app/website.
What I really struggle with is the following: adding a location block or as I understand it, include my upstream block into my downstream (correct my terms if I am wrong). So, have my url go from https://app.myweb.com/login to https://app.myweb.com/dashboard/login using the following configuration in nginx:
location /dashboard/ { # THIS IS WHAT I WANT TO ADD
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_redirect off;
proxy_read_timeout 90s;
proxy_pass http://127.0.0.1:5001;
}
All that happens is, if I type https://app.myweb.com/dashboard/ it doesn't go to https://app.myweb.com/dashboard/login as I would expect, but redirects back to https://app.myweb.com/login which 404's.
Any advice on what I am doing wrong?

Nginx changes POST to GET using proxy_pass

I want to use Nginx create a gateway to receive requests and pass them along to a network of microservices.
What I need Nginx to do is just act as a proxy server, taking the requests, passing them along to whatever service, and returning the response without any changes.
This is my configuration for my local setup:
server {
listen 8080;
location /api/register/ {
proxy_pass http://micro_auth_backend:8082;
}
location /api/location/ {
proxy_pass http://localhost:8088;
}
}
It works correctly for GET requests, but when doing a POST call, the server will always receive a GET response.
I have tried adding some more configs inside the location, such as this example below, but so far nothing has worked:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Any suggestions would be appreciated.
Thank you
Just removed the trailing slash on location:
location /api/register {
proxy_pass http://micro_auth_backend:8082;
}
Now it works.
you can add this code to your nginx.conf file. It works for me.
location /api/register/ {
proxy_pass http://localhost:8082;
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;
}
location /api/location/ {
proxy_pass http://localhost:8088;
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;
}

Ngnix: Multiple Websites Using a Shared IP on a Server with Multiple IP Adress

I am deploying multiple websites to an Ubuntu server equipped with Nginx. I also use the proxy_pass feature to pass the traffic to the service.
The problem is whichever websites is set on Nginx first, all incoming traffics are rerouted to.
I created 3 different .conf files in /etc/nginx/conf and here is the details for each:
subdomain1.conf
server {
listen <the second ip>:80;
server_name subdomain1.mydomain.com;
location / {
proxy_pass http://127.0.0.1:11111;
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;
}
}
subdomain2.conf
server {
listen <the second ip>:80;
server_name subdomain2.mydomain.com;
location / {
proxy_pass http://127.0.0.1:22222;
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;
}
}
subdomain3.conf
server {
listen <the second ip>:80;
server_name subdomain3.mydomain.com;
location / {
proxy_pass http://127.0.0.1:33333;
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;
}
}
Finally, I reload Nginx using the following command line:
sudo nginx -s reload
However, all incoming traffics for other subdomains (subdomain2 and subdomain3) are somehow passed to subdomain1. What I have noted so far is whichever set first, all incoming traffics are bound to it.

nginx as a reverse proxy

I'm trying to use nginx as a reverse proxy to a couple of web applications deployed within docker containers. I can only expose port 80 from the docker server, and want to allow access to shipyard and rabbitMQ management web app.
Ideally, users could access the services via:
http[:]//10.10.10.1/shipyard/
http[:]//10.10.10.1/rabbitmq/
After quite a bit of research, trial and error this is my nginx config:
upstream rabbitmq {
server 127.0.0.1:8888;
}
upstream shipyard {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name 10.10.10.1;
location /rabbitmq/ {
proxy_http_version 1.1;
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://rabbitmq/;
proxy_redirect default;
}
location /shipyard/ {
proxy_http_version 1.1;
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://shipyard/;
proxy_redirect default;
}
}
When I access either path the apps I run into a couple of problems, which I believe maybe related:
shipyard:
Tries to load files from http[:]//10.10.10.1/api/containers, when it should be http[:]//10.10.10.1/shipyard/api/containers
rabbitmq:
Everything appears to work, until the server attempts to make a restful call:
+++ PUT: http[:]//10.10.10.1/rabbitmq/api/queues///test2
The server response with 405 (Not Allowed). At first I thought the /// was the problem, that is how the rabbitMQ management application works.

Resources