Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Steady-Entertainment's avatar

larvel route() point to IP

Hello community,

When I use Laravels route() funciton and it returns

192.168.1.220/register

instead of

myDomain/register

so my application doesnt work on the internet

if I change my.env file

to

APP_URL=mydomain.com

it doenst change

0 likes
15 replies
Snapey's avatar

make sure you clear or re-cache the config after change.

Are you behind a proxy ? 192.168.x.x is a private IP

Steady-Entertainment's avatar

I am running the following script

cd /home/forge/offline.vision
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service php7.4-fpm reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    php artisan migrate --force
fi

npm install
npm run dev

php artisan config:cache

php artisan cache:clear
php artisan view:clear

php artisan route:cache
Steady-Entertainment's avatar

When I change

<form id="logout-form" action="{{ route('logout') }}" method="POST"

to

<form id="logout-form" action="/logout'" method="POST"

it works

but there are locations where i dont know how to replace the route function like:

<form id="logout-form" action="{{ route('logout') }}" method="POST"
Steady-Entertainment's avatar

I am not behind a proxy but I am using port forwarding on my firewall

translating incoming requests to go from 62.2.92.66 which is my public ip to use NAT to go to 192.168.1.220

Steady-Entertainment's avatar

Let me rephrase my question really simple:

Where does route() get the url / ip from?

function route($name, $parameters = [], $absolute = true)
    {
        return app('url')->route($name, $parameters, $absolute);
    }

And how can I change it?

Steady-Entertainment's avatar

on

offline.vision

you get the following output

 array:36 [▼
  "USER" => "forge"
  "HOME" => "/home/forge"
  "HTTP_CONNECTION" => "Keep-Alive"
  "HTTP_X_FORWARDED_SERVER" => "offline.vision"
  "HTTP_X_FORWARDED_HOST" => "offline.vision"
  "HTTP_X_FORWARDED_FOR" => "62.202.183.94"
  "HTTP_X_FORWARDED_PROTO" => "http"
  "HTTP_UPGRADE_INSECURE_REQUESTS" => "1"
  "HTTP_COOKIE" => "vsid=919vr3303037803930342; bfp_sn_rf_b10ce94cf299b167b74a6944e0aec9d4=Direct/External; bfp_sn_rt_b10ce94cf299b167b74a6944e0aec9d4=1587118183894; bafp=8f61a370- ▶"
  "HTTP_ACCEPT_ENCODING" => "gzip, deflate"
  "HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.5"
  "HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  "HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"
  "HTTP_HOST" => "192.168.1.220"
  "REDIRECT_STATUS" => "200"
  "SERVER_NAME" => "offline.vision"
  "SERVER_PORT" => "80"
  "SERVER_ADDR" => "192.168.1.220"
  "REMOTE_PORT" => "59530"
  "REMOTE_ADDR" => "192.168.1.1"
  "SERVER_SOFTWARE" => "nginx/1.17.3"
  "GATEWAY_INTERFACE" => "CGI/1.1"
  "SERVER_PROTOCOL" => "HTTP/1.1"
  "DOCUMENT_ROOT" => "/home/forge/offline.vision/public"
  "DOCUMENT_URI" => "/index.php"
  "REQUEST_URI" => "/"
  "SCRIPT_NAME" => "/index.php"
  "SCRIPT_FILENAME" => "/home/forge/offline.vision/public/index.php"
  "CONTENT_LENGTH" => ""
  "CONTENT_TYPE" => ""
  "REQUEST_METHOD" => "GET"
  "QUERY_STRING" => ""
  "FCGI_ROLE" => "RESPONDER"
  "PHP_SELF" => "/index.php"
  "REQUEST_TIME_FLOAT" => 1587566072.0716
  "REQUEST_TIME" => 1587566072
]

conclusion: You were totally right Snapey.

Do you also know how to solve this?

It is a bug that is virusing itself to through my entire application

Snapey's avatar

Did you check the docs linked earlier?

Steady-Entertainment's avatar

Yes I checked the link but I am not using a loadbalancer yet and I allowed all proxies now:

class TrustProxies extends Middleware
{
    protected $proxies = '*';
    /**
     * The trusted proxies for this application.
     *
     * @var array|string
     */
    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}
Steady-Entertainment's avatar

is there a place in the firewall or in the php.ini or on the webserver where I can change it?

Snapey's avatar
Snapey
Best Answer
Level 122

Your trusted proxy should be protected $proxies = ['192.168.1.1'];

Check that this middleware is enabled in Http\Kernel.php

Steady-Entertainment's avatar

I am not 100% sure but it seems to be working ... I dont understand why but that seems to do the trick

THANKS

Please or to participate in this conversation.