Configure NextCloud & Nginx Reverse Port Forward - Login Authentication Error

Brandon Lebedev

I have set up an nginx reverse proxy server on my web server, which is receiving SSL traffic, and reverse proxying it to port 8080 on my web server, which is an exposed port running the nextcloud docker image. I am able to log in from a desktop web browser, but I am not able to log in from my iPhone. When I log in from the app, I receive error message "Access Forbidden, Invalid Request." This Github issue identifies the issue as auth headers being removed from the request, though the solution it gives is for Apache, not for Nginx. I'm really not familiar with authorization headers. How would I modify my Nginx server directive to take care of the issue?

Current setup

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name cloud.foo.com;

    ssl_certificate /etc/letsencrypt/live/cloud.foo.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cloud.foo.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {
        proxy_pass         http://127.0.0.1:8080/;

        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   Host             $host;
    }
}
Richard Smith

You may need to add a setting to explicitly pass the Authorization header in the response from the proxied server.

For example:

location / {
    proxy_pass         http://127.0.0.1:8080/;

    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header   Host             $host;
    proxy_pass_header  Authorization;
}

Based on the reverse proxy settings I've seen for another authenticated service, it's probable that by default, Nginx does not pass the Authorization header from the response of a proxied server to a client. Although this is not listed in the documentation, it is probably necessary to avoid interference with the authentication modules.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Nginx reverse proxy for nextcloud not work

How to configure NGINX as a reverse proxy for different port numbers?

Nextcloud on apache and nginx as reverse proxy + SSL

Nextcloud share not working in nginx reverse proxy

Forward a port with NGINX

nginx - reverse proxy certificate authentication

Nginx reverse proxy for port 3001

How to configure nginx to forward websockets to a different process

NGinx forward websocket from 80 to websocket port

nginx forward to certain apache port on the basis of cookie

Nginx error with port 80

Configure Sonarqube with SSL with NGINX as reverse-proxy - Errorcode: SSL_ERROR_RX_RECORD_TOO_LONG

I'm getting an error in nginx while installing nextcloud?

Nginx forward from domain A port 8080 to domain B port 80

Nginx Reverse Proxy Websocket Authentication - HTTP 403

Configure Nginx reverse proxy subdomains with dynamic DNS

Configure Reverse Proxy on NGINX with Grafana on Windows

Nginx Reverse Proxy with Port Forwarding Not Working

NGINX: Rewrite url and reverse proxy to a different port

Doing an SSH reverse port forward without GatewayPorts enabled

Forward GoDaddy subdomain to a different port on the same server (reverse proxy)

Error with IP and Nginx as reverse proxy

Android USB Debugging Port Forward Error

Nginx ignores HTTP Authentication for WordPress login directory

nginx server forward request on custom port to node app

Mixed content error with Collabora CODE / Nextcloud / Traefik reverse proxy via docker-compose

Docker : how to (reverse) forward port to allow access to the host's localhost:PORT?

Reverse SSH dynamic port allotment error

nginx + vbulletin 500 error on login