Laravel在所有使用NginX配置的路由上返回404

时间:2020-03-22 22:34:34

标签: php laravel nginx

我已经尝试解决这一问题了一天。我已经检查了所有类似的问题并做了同样的事情,但这似乎不起作用。

我当前正在服务器上运行节点JS应用,现在我打算向其中添加laravel。但是所有路由都会返回laravel 404错误页面。

这是配置文件。

server {

  listen 80;
  listen [::]:80 ipv6only=on default_server;

  root /var/www/html/dlabs.cloud-File-Service/public;

  index index.html index.htm index.php;


  server_name dlabs.com.ng;


  location /auth/ {

    proxy_pass http://localhost:3000;
    proxy_pass_header Server;
    proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header REMOTE_ADDR $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location /file-service/ {

    try_files $uri $uri/ /index.php?$query_string;

  }


  location / {

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


  location = /favicon.ico {

    access_log off; log_not_found off;
  }
  location = /robots.txt {

    access_log off; log_not_found off;
  }

  error_page 404 /index.php;

  location ~ \.php$ {

    fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    include fastcgi_params;
  }


  location ~ /\.(?!well-known).* {

    deny all;
  }


  location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {

    expires 5d;
  }

  # deny access to . files, for security
  #
  location ~ /\. {

    log_not_found off;
    deny all;
  }
}

PHP版本为7.3。

/ auth /完美运行。

2 个答案:

答案 0 :(得分:0)

定义路线的方式可能会出现问题。请向我们提供Laravel的routes目录中定义的所有路由。

答案 1 :(得分:0)

添加try_files $uri $uri/ /index.php$is_args$args; 到 nginx.conf

in => /etc/nginx/nginx.conf