G
G
Gleb Starkov2018-04-23 14:20:55
Nginx
Gleb Starkov, 2018-04-23 14:20:55

Laravel dynamic robots.txt plus nginx php-fpm not working?

We use dynamic robots.txt, the text of which is stored in the database and configured in the admin panel.
Laravel has a route for this:

Route::get('/robots.txt', function(){
    $settings = \App\Block::where('kind', 'robots.txt')->first();
    $fileText = $settings->code;
    $headers = ['Content-type'=>'text/plain','Content-Length'=>sizeof($fileText)];
    return Response::make($fileText, 200, $headers);
});

But doesn't work via nginx + php-fpm

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2018-04-23
@v_decadence

What and how exactly does not work?
Maybe you have a real robots.txt file and nginx gives it in the first place. In this case, you need to remove it.

I
iljaGolubev, 2018-04-23
@iljaGolubev

1. The nginx config for this site should not contain the line location = /robots.txt { access_log off; log_not_found off; }
2. Route with Streamed Downloads

Route::get('/robots.txt',function(){
   return  response()->streamDownload(function () {
       echo \App\Block::where('kind', 'robots.txt')->first()->code;
   }, 'robots.txt', ['Content-Type'=>'text/plain'],'inline');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question