Search code examples
laravelubuntularavel-5.3ubuntu-16.04

Homepage loads, no other pages do


I have my laravel project on my nginx ubuntu webserver.

I can see the homepage, but all of the other pages fail.

Does anyone know why this is happening?

I suspect it's something to do with this line in the sites available file:

try_files $uri $uri/ =404;

Could anyone post their own sites available file?


Solution

  • Try the following

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

    Full config:

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        root /path/to/your/laravel/public;
        index index.html index.htm index.php;
    
        server_name your_domain.com;
        charset utf-8;
    
        gzip on;
        gzip_vary on;
        gzip_disable "msie6";
        gzip_comp_level 6;
        gzip_min_length 1100;
        gzip_buffers 16 8k;
        gzip_proxied off;
        gzip_types text/plain text/css text/xml application/javascript application/json application/xml application/xml+rss;
    
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$is_args$args;
        }
    
        location = /favicon.ico { access_log off; log_not_found off; }
    
        location = /robots.txt { access_log off; log_not_found off; }
    
        access_log off;
        error_log /var/log/nginx/your_error.log error;
    
        sendfile off;
    
        client_max_body_size 100m;
    
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors off;
                fastcgi_buffer_size 16k;
                fastcgi_buffers 4 16k;
        }
    
        location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)$ {                expires 1M;
                access_log off;
                add_header Cache-Control "public";
        }
    
        location ~* \.(?:css|js)$ {
                expires 7d;
                access_log off;
                add_header Cache-Control "public";
        }
    
        location ~ /\.ht {
                deny all;
        }
    

    }