make sure you clear or re-cache the config after change.
Are you behind a proxy ? 192.168.x.x is a private IP
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
make sure you clear or re-cache the config after change.
Are you behind a proxy ? 192.168.x.x is a private IP
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
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"
the ip 192.168.1.220 is from my webserver
the address is offline.vision
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
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?
from app('url')
but APP_URL is: offline.vision
It reflects what it sees on the incoming request. So, if you are using NAT it has no idea about the external IP
It should though know about the URL, but its definitely to do with trusted proxies.
https://laravel.com/docs/7.x/requests#configuring-trusted-proxies
Try dumping the request()->server() and check the HTTP_HOST
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
Did you check the docs linked earlier?
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;
}
still doesn't work
is there a place in the firewall or in the php.ini or on the webserver where I can change it?
Your trusted proxy should be protected $proxies = ['192.168.1.1'];
Check that this middleware is enabled in Http\Kernel.php
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.