【问题标题】:laravel routing not working on ip addresslaravel 路由在 IP 地址上不起作用
【发布时间】:2020-01-26 11:40:31
【问题描述】:

我在 vps 服务器上实现 laravel,只有一个 ip 地址,没有域。

它的工作并显示索引文件,但路由不工作并显示 404 未找到页面。

这是我的 web.php 文件:

<?php


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

Route::get('/test' , function(){
    return 'this is test route';
});

并在 .env 文件中设置 ip:

APP_URL=http://178.63.245.92

这是我的 vps 的 IP 地址:http://178.63.245.92/

当我说:http://178.63.245.92/test 它说:

Not Found
The requested URL /test was not found on this server.

必须做什么。

谢谢。

【问题讨论】:

  • 您使用 Apache 作为 Web 服务器吗?
  • 尝试清除缓存:php artisan cache:clear
  • 是的,它是 centos 7 上的 apache
  • 你的虚拟主机设置对了吗?
  • @script47 我运行 php artisan cache:clear 但它没有解决问题

标签: php laravel .htaccess dns routing


【解决方案1】:

@IlGala 感谢您指出 my mod_rewrite 模块,mymod_rewrite 模块已启用,但我在您启用 my mod_rewrite 后读取了 here,您必须允许 Apache 读取位于 /var/ 下的 .htaccess 文件www/html 目录。 我按照结构在该页面上的说明授予访问权限并已解决。

感谢每一个人。

【讨论】:

    【解决方案2】:

    您可以使用此命令设置路由到所需的 IP 地址

    php artisan serve --host 178.63.245.92 --port 80
    

    【讨论】:

    • 我为它服务并说:ErrorException : chdir(): No such file or directory (errno 2)
    • 这篇文章可以帮到你:) stackoverflow.com/questions/30873773/…
    • 如果地址已经在使用中,那是因为一个子进程还活着。一旦找到并杀死该进程,您将能够重新发出该命令。
    • @Suvin94 谢谢,我解决了这个问题并再次提供服务,它说:“无法在 178.63.245.92:80 收听(原因:地址已在使用中)”
    • @Jim Grant 如果我重启服务器会解决吗?
    猜你喜欢
    • 2015-03-18
    • 1970-01-01
    • 2016-09-07
    • 2014-09-04
    • 2015-03-27
    • 2014-08-28
    • 2016-02-27
    • 1970-01-01
    • 2016-04-18
    相关资源
    最近更新 更多