簡體   English   中英

Laravel路由不起作用,只有根路由起作用

[英]Laravel routes are not working only root route is working

在運行composer install命令之后,我已經在EC2實例(類型ubuntu 16.04)上克隆了laravel項目。

我已經根據我的本地機器更改了/etc/nginx/site-available/default配置

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html/myproject/public;

    charset utf-8;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name myServerIpAddress;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }


    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

現在,當我打開服務器的IP地址時,它正確顯示了我的/路由,但是當我嘗試打開/login/register卻顯示未找到404

我的nginx版本是(1.10.0)我的php版本是(7.0.18)

我還檢查了日志文件,但未顯示任何錯誤

謝謝

使用當前配置,在請求/login ,nginx將嘗試查看是否存在一個名為/var/www/html/myproject/public/login的文件,以及是否存在一個名為/var/www/html/myproject/public/login/的文件夾/var/www/html/myproject/public/login/存在,如果都不存在則返回錯誤404。

這不是您期望的,因為您沒有創建名為login的文件,而只是在Laravel的路由器內創建了一條路由。 因此,您必須以某種方式配置nginx,以便在每次對此vhost發出請求時,都將調用公共目錄的index.php文件,然后該框架將能夠將該請求所針對的URL與您注冊的路由進行比較。

正如Laravel網站上記錄的那樣 ,您應該編輯配置以添加以下位置塊,以便將所有請求(除了對靜態資源的請求之外)重定向到index.php ,並將原始查詢作為參數:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM