EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.08k stars 1.02k forks source link

HTTP urls instead of HTTPS are generated behind nginx proxy #5750

Closed 4d4ch4u32 closed 1 year ago

4d4ch4u32 commented 1 year ago

When I run my Symfony application with EasyAdmin (latest version) behind a nginx proxy, the ajax requests are blocked by browser.

Symfony runs without SSL behind a nginx proxy with SSL, so the URLs should be generated with https instead http. Maybe this is not a bug, but: how can I solve that?

xaviermarchegay commented 1 year ago

Look at the comments from this issue: https://github.com/EasyCorp/EasyAdminBundle/issues/3542

Especially this one: https://github.com/EasyCorp/EasyAdminBundle/issues/3542#issuecomment-659620659

4d4ch4u32 commented 1 year ago

I've added the configuration for trusted proxies, but it changes nothing.

This is my proxy configuration:

  location / {
    auth_basic           "No trespassing, please!";
    auth_basic_user_file /srv/mhg/htpasswd;

    proxy_pass http://localhost:8080/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    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 X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Port $server_port;
  }

and this is my configuration on Symfony's side:

framework:
  secret: '%env(APP_SECRET)%'
  #csrf_protection: true
  http_method_override: false
  handle_all_throwables: true
  trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port']
  trusted_proxies: '%env(TRUSTED_PROXIES)%'

The content of .env-var TRUDSTED_PROXIES = 127.0.0.1,localhost.

xaviermarchegay commented 1 year ago

You can also use relative urls to avoid this issue.

https://symfony.com/bundles/EasyAdminBundle/4.x/dashboards.html#dashboard-configuration (search for generateRelativeUrls)

4d4ch4u32 commented 1 year ago

Generating relative urls are solving this issue, thanks.