Framework: url() generates url with index.php 5.6

Created on 22 Apr 2018  路  9Comments  路  Source: laravel/framework

  • Laravel Version: 5.6
  • PHP Version: 7.2.3
  • Database Driver & Version:

Hey. Faced the problem that the function of the url('/') generates the url along with the index.php. I used nginx + nginx unit

Nginx config

server {
    listen       80;
    server_name  beauty.local;

    root /home/home/myawesomeproject/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        proxy_pass       http://127.0.0.1:8300;
        proxy_redirect   http://127.0.0.1:8300/ /;
        proxy_read_timeout 60s;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Unit config

{
  "listeners": {
    "*:8300": {
      "application": "myawesomeproject"
    }
  },
  "applications": {
    "beauty": {
      "type": "php",
      "processes": 5,
      "root": "/home/home/myawesomeproject/public",
      "index": "index.php",
      "user": "www-data",
      "group": "www-data"
    }
  }
}

All 9 comments

What's the value of APP_URL in your .env file?

@staudenmeir same as in settings nginx - beauty.local

And url('/') gives you 'beauty.local/index.php'?

@staudenmeir yes, dd(url('/')); in http://beauty.local/ gives me "http://beauty.local/index.php"

@Hunternnm could you post the result of $request->headers->all() ?

@craigpaul

array (size=12)
  'host' => 
    array (size=1)
      0 => string 'beauty.local' (length=12)
  'x-real-ip' => 
    array (size=1)
      0 => string '127.0.0.1' (length=9)
  'x-forwarded-for' => 
    array (size=1)
      0 => string '127.0.0.1' (length=9)
  'x-forwarded-proto' => 
    array (size=1)
      0 => string 'http' (length=4)
  'connection' => 
    array (size=1)
      0 => string 'close' (length=5)
  'user-agent' => 
    array (size=1)
      0 => string 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0' (length=76)
  'accept' => 
    array (size=1)
      0 => string 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' (length=63)
  'accept-language' => 
    array (size=1)
      0 => string 'en-US,en;q=0.5' (length=14)
  'accept-encoding' => 
    array (size=1)
      0 => string 'gzip, deflate' (length=13)
  'cookie' => 
    array (size=1)
      0 => string 'XSRF-TOKEN=eyJpdiI6IjZpSjc4c0luZ1JtYWRVSnJvYTRSXC93PT0iLCJ2YWx1ZSI6IkNjdE8xWlU3SXQzUDZRYytha3A2V1wvVGFYa0YxaUVncVI5YnN1d0xaSnh1bTNIR1pER0RuRjVNcWlEcmxZdXZZb1Y5SEVjbXdrUnpiaVhmSndBc0EyUT09IiwibWFjIjoiZDc1YzQ3OWFjNGZkNjEwNGFkMGI2ZmQ2NTNhOTg4NmIwMTgyMTA4YzFlNmE4MzdhZWZmYmU0MGQwMGI2MzliMyJ9; laravel_555_session=eyJpdiI6Im0rR1ZXeGNZZitadXV6VUNsSWpKV1E9PSIsInZhbHVlIjoicFdRck5jcFQzU0ljY2FDaGdQYVlQVUx5ZXNZRXFRcE5pVVNYRTRKK1FPRTJudVFjYlJcLzBiUHhiNlg5aVJzbzV5K09CZ3pvaTdYWHlMMm0yblowWnN3PT0iLCJtYWMiOiI4YTliNTMyZTE2N2Q'... (length=587)
  'upgrade-insecure-requests' => 
    array (size=1)
      0 => string '1' (length=1)
  'cache-control' => 
    array (size=1)
      0 => string 'max-age=0' (length=9)

Hmmm...what about $request->server->all()? It鈥檚 definitely something to do with the variables / headers being set, just not sure which one.

@craigpaul hmm, really 'REQUEST_URI' => string '/index.php' (length=10). Thanks for the help, I will deal with the settings

Changing configuration to this solved the problem

server {
    listen       80;
    server_name  beauty.local;

    root /home/home/Projects/beauty/public;
    index index.php;

    location / {
        try_files $uri @rewrite;
    }

    location @rewrite {
        proxy_pass       http://127.0.0.1:8300;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Was this page helpful?
0 / 5 - 0 ratings