【问题标题】:Laravel 5 Nginx redirects to 404Laravel 5 Nginx 重定向到 404
【发布时间】:2018-09-26 12:20:23
【问题描述】:

我的 Laravel 5 网站重定向到 404。它安装在一个文件夹中。

它使用 Laravel 5.6 和 Nginx 1.12.1

它正在重定向到 404 而不是我的项目。计划部署多个站点。

https://example.com/staging/project/ -> 重定向到 404 而不是打开页面。

找到 nginx 配置

server {
    listen       443 ssl http2 default_server;
    listen       [::]:443 ssl http2 default_server;
    server_name  _;
    root         /var/www/example;
    index   index.php index.html index.htm;

    ssl_certificate "/etc/letsencrypt/live/example.com/fullchain.pem";
    ssl_certificate_key "/etc/letsencrypt/live/example.com/privkey.pem";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    location ^~ /staging/project {
      alias /var/www/example/staging/project/public;
      index index.php
      try_files $uri $uri/ /index.php$is_args$args @laravel1;

    location ~ \.php {
       try_files $uri =404;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_param  SCRIPT_FILENAME $request_filename;
       fastcgi_param SCRIPT_NAME $fastcgi_script_name;
       fastcgi_split_path_info ^(.+\.php)(.*)$;
       fastcgi_index index.php;
       include /etc/nginx/fastcgi_params;
    }
  }

   location @laravel1 {
       rewrite /staging/project/(.*)$ /staging/project/index.php?/$1 last;
   }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

【问题讨论】:

  • 你重启nginx了吗?
  • 是4次以上。

标签: php laravel nginx laravel-5 nginx-location


【解决方案1】:

这里只有一件事是错误的,我认为你需要改变,你快到了。

改变

root         /var/www/example;

root         /var/www/example/public;

每次更改 xxx.conf 文件时也总是重启 Nginx。

Sudo service nginx restart

【讨论】:

  • 我的 root 有一些其他的 php 应用程序,所以无法在 root 路径中添加 public
  • 当你安装 Laravel 时,你会看到结构,并且安装中有 public 文件夹/目录,你必须在你的 nginx conf root 中指向它。除此之外,您的框架永远不会读取它的入口点 index.php 并且它总是会被 Nginx 吐出 404 页面。
猜你喜欢
  • 1970-01-01
  • 2015-08-18
  • 2020-07-17
  • 1970-01-01
  • 2015-04-08
  • 1970-01-01
  • 2013-06-18
  • 1970-01-01
相关资源
最近更新 更多