Jump to content

Add X-Forwarded-For Header to admin pages


elstego

Recommended Posts

Dear community

I'm using ezoic and their proxies require me to add a header to admin pages. Without the header i get a redirect loop when i login back to the login page. What i tried is adding the header to [adminfolder]/index.php but this makes the backoffice really slow and seems wrong, because i modify a core file, right? Where can i place the code, so that it stays in future updates? Or is there even a workaround with nginx so that i dont need to modify any files?

This is the code that i want to add:

// Use X-Forwarded-For HTTP Header to Get Visitor's Real IP Address
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
    $http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
    $_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}

 

PS version: 1.7.6.0
Server: nginx
OS: Debian 10

 

Thanks a lot!

Link to comment
Share on other sites

1 hour ago, prestol said:

why you do x-forwarded host in the application and not in nginx?

Can you tell me how to? I'm not knowing much about these headers. I tried adding:

location /adminXXXXX/
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    if (!-e $request_filename) {
        rewrite ^/.*$ /adminXXXXX/index.php last;
    }
}

But this is not working

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...