主页加载,没有其他页面

时间:2016-10-27 07:47:10

标签: laravel ubuntu laravel-5.3 ubuntu-16.04

我在我的nginx ubuntu网络服务器上有我的laravel项目。

我可以看到主页,但所有其他页面都失败了。

有谁知道为什么会这样?

我怀疑它与网站可用文件中的这一行有关:

try_files $uri $uri/ =404;

有人可以发布自己的网站可用文件吗?

1 个答案:

答案 0 :(得分:2)

尝试以下

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

完整配置:

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;
    }

}