Too many redirects while setting up gogs with nginx - nginx

I am setting up gogs on nginx server.I also have cpanel/apache hosted on the same server.I am redirecting my gogs call using .htaccess from cpanel.My nginx configuration is
server {
listen 9800;
server_name <my_domain>;
proxy_set_header X-Real-IP $remote_addr; # pass on real client IP
location / {
proxy_pass http://localhost:8000;
}
}
It is working fine if i am using direct ip from browser but when i am using domain it throwing ERR_TOO_MANY_REDIRECTS error on browser.

Related

No host name in browser Nginx

I'm having a problem with nginx server.
When I deploy it and type my hostname in the broker window it will find the page, but it will display IP, not the host name. I tried few things and it always fails. It is strange because I used this before and worked.
I can add that I'm using it as a reverse proxy.
DNS correctly redirects to IP.
But no hostname is shown.
I tried this on AWS EC2 and on digital ocean.
My basic conf is:
server {
listen 80;
listen [::]:80;
server_name hostname.com;
location / {
proxy_pass http://api:8000/index;
proxy_set_header Upgrade $server_name;
proxy_set_header Host $server_name;
}
}

NGINX Proxy pass to external site that has internal redirect

i'm trying to configure an nginx proxy that hide an internal site via the proxy pass but without success.
the config i used is
location /internal1/ {
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_connect_timeout 15;
proxy_read_timeout 180;
proxy_pass http://internal1/;
}
upstream internal1 {
server a.b.c.d:80;
}
the problem is that when i try to reach the a.b.c.d site it redirect to a login page that sould be http://a.b.c.d/login and after i login it redirect at another page http://a.b.c.d/device/config . with the proxy it redirect to http://mysite/login and http://mysite/device/config
that make the proxy do not work and show me resource not found and i couldn not see any of the pages.
If i change the proxy_pass value to http://a.b.c.d/login/ it show the login page at http://mysite/internal1 and after i login it show no resource found because it try to reach http://mysite/device/config.
someone have some suggestion on how to configure it in the proper way?
thanks for all the answer
EDIT:
sorry for the late answer but i got very busy in the meanwhile, anyway that solution work for 1 device but now all my device connected go only that device "internal" page and i cannot differentiate between more cause nginx do not support the same location in multiple config ( all device have ip/page1 )
location /page1/
{
proxy_pass mysite/internal1/page1;
proxy_redirect off;
proxy_set_header Host $host;
}
EDIT2:
unlucky it's not possible to expose all device to internet directly. the solution i found is:
create a custom DNS subdomain and then create a different nginx server block for every device with his own location and future redirect/proxy ecc...
If you want to expose the web UI of all your devices that live in the internal network to be accessible through Internet - then you will have to create a subdomain (and a corresponding virtual host config) for each device.
Suppose that the domain that points to your nginX is mydevices.net and that you have 2 devices - on 192.168.2.10 and 192.168.2.20
Then your nginX config will look like this:
server {
listen 80;
server_name dev1.mydevices.net;
location / {
proxy_pass internal1;
proxy_redirect default;
}
}
upstream internal1 {
server 192.168.2.10;
}
server {
listen 80;
server_name dev2.mydevices.net;
location / {
proxy_pass internal2;
proxy_redirect default;
}
}
upstream internal2 {
server 192.168.2.20;
}

Issue accessing plotly dash behind nginx

I have a dash plotly running on a VM with ip address 192.168.8.3 on port 5050. Locally, I can access the dashboard using the url http://192.168.8.3:5050.
Now I am trying to enable access via Nginx on http://myserver.com/dashboard/devs. However, when i try access it, in the browser console there is some files not found:
GET http://myserver.com/assets/header.css?m=1597279663.0
GET http://myserver.com/assets/typography.css?m=1597279663.0
This is my nginx configuration:
server {
server_name myserver.com;
location /dashboard/devs {
rewrite ^/(dashboard/devs)/(.*) /$2 break;
proxy_pass http://192.168.8.3:5050;
proxy_set_header X-Real_IP $remote_addr
...
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
Finally it was resolved using flask to redirect "/" requests to "/dashboard/devs/". The nginx configuration was left untouched.

flask oidc auth callback redirects to http instead of https

This is my first attempt to deploy a plotly dash python web app. I followed below tutorials to get going
digital ocean flask app with gunicorn and nginx
Okta authentication for flask app using OpenIdConnect
The app runs fine on an ec2 instance with nginx and gunicorn all in docker containers. The redirect to okta for authentication and back works fine (using ec2 instance public ip)
After setting redirect for domain name via aws load balancer (HTTPS) it started failing complaining 404 as url scheme returned was http instead of https.
First i added OVERWRITE_REDIRECT_URI config with https which fixed incorrect redirect uri problem on okta side
Then tried ProxyFix and all options in below SO posts but after redirect to /authorization-code/callback?code=<long code value>, the response always comes back with http://<my_website_name>/<page> instead of https
Make Flask's url_for use the 'https' scheme in an AWS load balancer without messing with SSLify
X-Forwarded-Proto and Flask
I'm stuck at this point, what am i missing here?
Thanks
nginx conf.d/conf
upstream app_server {
server dash:8050;
}
server {
listen 80;
server_name _;
location / {
try_files $uri #proxy_to_app;
}
location #proxy_to_app {
gzip_static on;
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_buffering off;
proxy_redirect off;
proxy_pass http://app_server;
}
}

Nginx preserve $request_uri

I'm not sure if the behavior I want is actually possible natively with nginx but here goes.
I have a server running on port 81 with the following nginx config:
CONFIGURATION OF SERVER1 NGINX
server {
listen 81;
server_name SERVER_DNS_NAME;
location /server1 {
proxy_pass http://127.0.0.1:8084/;
proxy_set_header Host $host;
}
location / {
proxy_pass http://127.0.0.1:8084;
proxy_set_header Host $host:$server_port;
}
}
I have another server running on port 82 with similar configuration. Now what'd i'd like to do is be able to visit them both from port 80 with just different uris.
For example: URL/server1 would take me to the first server, and URL/server2 would take me to the second.
CONFIGURATION OF NGINX LISTENING ON PORT 80
server {
listen SERVER_IP:80;
location /server1{
proxy_set_header Host $host;
http://SERVER_IP:81;
}
location /server2 {
proxy_pass http://SERVER_IP:82;
proxy_set_header Host $host;
}
This works fine when I go to URL/server1. I am successfully routed to the main page on server1. However as soon as I click any of the links present on the page on server1 I get a 404. This is because the site tries to go to URL/some_subdir_of_server1 (for which there is no mapping) rather than doing URL/server1/some_subdir_of_server1. Is this behavior doable? If so how?
Thanks!
Be careful with trailing slashes: in your example, you have
proxy_pass http://SERVER_IP:81/; which will set the proxy URL to root /

Resources