【问题标题】:Laravel routes getting not found on nginx/1.8在 nginx/1.8 上找不到 Laravel 路由
【发布时间】:2016-04-16 03:51:32
【问题描述】:

我使用 laravel 5.1nginx/1.8 这是我第一次使用 Nginx 服务器

当我尝试访问 laravel 应用主页时,路线运行良好

get('/', function () {
   return view('welcome');
});

但是当我尝试访问任何其他页面时

get('/home', function () {
    return 'Home Page';
   // Or Blade Page 
  //return view('home');
});

Nginx 返回

我在/etc/nginx/nginx.conf上的设置文件

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
  worker_connections 1024;
}

http {
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost;
    #root        /usr/share/nginx/html;
    root         /var/www/nginx/html;
    index        index.php index.html index.htm;

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

    location / {

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

    location ~ \.php$  {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
 } 

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

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

更新 /var/log/nginx/error.log的最后结果

#3 /var/www/nginx/html/laravel/vendor/laravel/framework/src/Illuminate /Foundation/Exceptions/Handler.php(49): Monolog\Logger->错误(对象(Symfo 2016/01/11 22:59:38 [错误] 22510#0: *31 "/var/www/nginx/html/laravel/" 的目录索引被禁止,客户端:127.0.0.1,服务器:_,请求: “GET /laravel/ HTTP/1.1”,主机:“localhost”

注意:html/laravel -> laravel 是应用名称

有什么建议吗?

【问题讨论】:

    标签: php laravel nginx laravel-5.1


    【解决方案1】:

    Root 需要指向你的 laravel 安装的公共文件夹。如果你已经将 laravel 安装到/var/www/nginx/html,那么应该是:

     root         /var/www/nginx/html/public  
    

    【讨论】:

    • html 这是包含我的 appsdir 我认为您的意思是 root /var/www/nginx/html/laravel/public 无论如何我都尝试了但是我仍然返回404 error
    • 检查您的公用文件夹在哪里,然后进行设置。如果您在子目录而不是自己的域中使用 laravel,则需要在您的 htaccess 文件中进行设置。
    • 感谢您的关心,我的应用名称是 laravel,它在 html 目录中,现在是我的 root /var/www/nginx/html,如果您看到在这种情况下应该设置 htaccess file,请帮助我
    • 您是否尝试通过domain.comdomain.com/laravel 访问该站点?如果您应该使用 nginx.conf 或 .htaccess,这会有所不同。
    • 我在 localhost 服务器上,我通过 localhost/laravel/public 访问站点,查看错误图片,如果我想访问 localhost/laravel/public/home,我收到错误消息
    猜你喜欢
    • 2015-10-08
    • 2014-05-30
    • 2016-06-08
    • 2016-11-15
    • 2017-03-12
    • 2020-03-26
    • 1970-01-01
    • 2020-04-14
    • 2017-06-11
    相关资源
    最近更新 更多