0

I'm running laravel serve on a local ip, and using a local ProxyPass server to reverse a public domain to that local ip.

The only problem is that when im using {{asset('...')}} laravel is placing the ip in front of the location of that asset. This will result in a 404 for that requested file.

Example: php artisan serve --host=192.168.178.2 --port=1234

My ProxyPass server passes all requests from example.com tot that local server.

This works, but on the places where I have used {{asset('...')}} in my code there is not 'example.com/css/app.css' but is '192.168.178.2/css/app.css'

Is there a way to serve on a IP, but laravel thinks its on a domain?

UNTITLED.PNG
  • 471
  • 1
  • 5
  • 12
  • Does anything here help you? https://stackoverflow.com/questions/29912997/laravel-routes-behind-reverse-proxy – Mike Nov 15 '18 at 23:41
  • Also try setting `ProxyPreserveHost On` in your Apache config file. That might be easier than anything else there. – Mike Nov 15 '18 at 23:45
  • Thanks for the link, sadly that code is for 5.5, i'm on 5.7 and there is no routes.php file there. But I think that may be the solution, just not to my version. I dont want my proxy server to change content that it is pushing trough. Laravel needs to do that. And I don't think ProxyPreserveHost On will work. Because larvel is setting that ip in the code, not my proxy or php artisan serve. – UNTITLED.PNG Nov 15 '18 at 23:49
  • I need this for Laravel 5.7: [link](https://stackoverflow.com/a/29913894/7257689) but I don't have the ```routes.php``` file – UNTITLED.PNG Nov 15 '18 at 23:53
  • `ProxyPreserveHost On` is precisely to retain the requested hostname when proxying. It does not change the content. Give that a try and get back to me. – Mike Nov 15 '18 at 23:55
  • Also, the routes files for 5.7 are stored in the `routes` subdirectory. You want `routes/web.php`. – Mike Nov 15 '18 at 23:57

1 Answers1

1

I found the solution, thanks to Mike!
Because of the old Stack Overflow post he advised me to visit. I found some new search terms for google. And then I found a GitHub post that just works with the latest Laravel 5.7.

Add the following code to app/Providers/RouteServiceProvider.php

public function boot()
{
    parent::boot();

    /** @var \Illuminate\Routing\UrlGenerator $url */
    $url = $this->app['url'];
    // Force the application URL
    $url->forceRootUrl(config('app.url'));
}
UNTITLED.PNG
  • 471
  • 1
  • 5
  • 12