ActionController::InvalidAuthenticityToken when using nginx to proxy https requests to other nginx (http) to proxy to rails (http)

srghma

I have following server structure:

  1. first nginx, that redirects all requests to nginx in docker container. I want it just to handle https and proxy requests to nginx that cant handle https

Full config

Related config (nginx-recommended-proxy-headers here) (I just tried every header that could help, didn't work):

location / {

    proxy_pass http://127.0.0.1:23000;


    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header X-Forwarded-Port $server_port;

    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header X-Forwarded-Protocol https;
    proxy_set_header X-Url-Scheme https;
    proxy_set_header X-Forwarded-Host $host:$server_port;

    proxy_set_header X-Real_IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_pass_header Set-Cookie;

    proxy_buffering off;
    proxy_ssl_session_reuse off;

    include /nix/store/avmqrlsy7dfh6bz1r6yzw3wvrvb0wzf1-nginx-recommended-proxy-headers.conf;
}
  1. nginx in docker container. It glues rails server and responsivefilemanager. It exists to allow tesing of both server and filemanager, but does not handle https.

Docker-compose

  nginx:
    stdin_open: true
    tty: true
    extends:
      file: chunks/nginx.yml
      service: nginx
    build:
      args:
        - NGINX_CACHE=on
    ports:
      - 23000:80
    env_file:
      - ./envs/filemanager-static-path.env
      - ./envs/carrierwave-dirs.env
    environment:
      - BACKEND_URL=http://be:3000
      - FILEMANAGER_URL=http://filemanager:80
    volumes:
      - filemanager_upload_data:/filemanager_upload_dir
      - carrierwave_public_upload_data:/public_upload
      - carrierwave_cache_data:/carrierwave_cache_dir
      - ${SOURCE_DIR:-..}:/public
    depends_on:
      - be
      - filemanager

Full config Related config

  location / {
    proxy_pass     $BACKEND_URL;
    proxy_http_version 1.1;

    proxy_set_header Host       $http_host;
    proxy_set_header Upgrade    $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Accept-Encoding "";
    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 X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-Host $host;

    proxy_buffering  off;
    proxy_ssl_session_reuse off;
  }
  1. rails server, just rails server, default prod config

And with this config I have ActionController::InvalidAuthenticityToken issue. enter image description here

Please help me. How this should work? What rails is expecting? https worked with this config when I had only 1 nginx and backend.

srghma

I've updated nixpkgs and issue disappeared

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ActionController::InvalidAuthenticityToken at login using NGINX and Rails

nginx reverse proxy redirects to http instead of https

NGINX reverse proxy to HTTP

HTTP nginx to HTTPS proxy_pass returns 504 BAD Gateway

how to handle nginx reverse proxy https to http scheme redirect

Nginx redirect https->http(reverse proxy)->port(docker container)

docker and jwilder/nginx-proxy http/https issue

Nginx config to proxy pass to external ip and port (https -> http)

NGINX proxy_pass same protocol (http/https)

Nginx reserve-proxy https and http connect error

Nginx - Redirect HTTP to HTTPS in Reverse Proxy to Remote Site

nginx openai cache proxy (http listener, https upstream) inside docker

Rails 5 ActionController::InvalidAuthenticityToken on Production Enviroment Nginx

Slow nginx behavior when using as reverse proxy for https

Nginx proxy when $http_user_agent matches mobile

nginx reverse HTTP proxy - what behavior when all upstreams are unavailable?

Proxy for requests with grunt only works with HTTP (and not HTTPS)

Proxy http and https requests with one virtualhost in Apache

NGINX Reverse proxy with HTTPS

modify HTTP status code of proxy result in nginx

Nginx Reverse Proxy Websocket Authentication - HTTP 403

Nginx: redirect custom domain http requests to https

Redirect Elastic Beanstalk HTTP requests to HTTPS with nginx

Problem with iframe serving my Domino XPages solution (with Nginx proxy) adds JS code to redirect using http (while site is https)

performing HTTP requests with cURL (using PROXY)

HTTP/HTTPS Proxy and FFmpeg

Nginx rewrite http to https and proxy to another port, ERR_TOO_MANY_REDIRECTS error

How to get Elastic Beanstalk nginx-backed proxy server to auto-redirect from HTTP to HTTPS?

Tomcat behind Nginx: how to proxy both HTTP and HTTPS, possibly on non-standard ports?