【问题标题】:Not able to access laravel routes in apache2 server无法访问 apache2 服务器中的 laravel 路由
【发布时间】:2017-10-24 09:58:48
【问题描述】:

我已经为我的服务器部署了一个新的 laravel 安装,同时我将我的 apache2 配置如下:

我在/etc/apache2/sites-available/ 中添加了000-default.conf 文件,如下所示:

DocumentRoot /var/www/html

 <Directory /var/www/html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
    Require all granted
 </Directory>

我已将 laravel 安装到 /var/www/html/stellar 文件夹中,现在我可以通过以下方式访问我的安装:

http://52.39.175.55/stellar/public/

但是在调用路由时它不起作用,喜欢

http://52.39.175.55/stellar/public/oauth/token

截图如下:

但假设我通过这个调用:

http://52.39.175.55/stellar/public/index.php/oauth/token

我得到了访问权限,

我尝试将我的public/.htaccess 文件更改为如下内容:

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On
RewriteBase /stellar

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

还是没有变化,帮帮我吧。

【问题讨论】:

  • 你启用了 mod_rewrite 吗?运行sudo a2enmod rewrite
  • @Troyer 我该如何检查?这是我完整的 php 信息52.39.175.55/info.php
  • Mod_rewrite 在 phpinfo() 中不可见。您可以通过以下方式查询:apache2ctl -M
  • @Troyer 我做到了,但这对我没有帮助。我可以看到rewrite_module (shared) 在输入apache2ctl -M 时可用。

标签: apache laravel .htaccess ubuntu-server


【解决方案1】:

/etc/apache2/sites-available/ 上的虚拟主机应如下所示:

<VirtualHost *:80>
    DocumentRoot "/var/www/html/stellar/public"
    ServerName yourdomain.com
    <Directory /var/www/html/stellar/public>
      AllowOverride All
    </Directory>
</VirtualHost>

然后重新启动apache2,它应该可以工作了。

我几乎不建议您复制 000-default.conf 文件,重命名它并包含 VirtualHost,然后使用 a2ensite 命令启用它,只是因为它更易于管理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 2014-11-25
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    相关资源
    最近更新 更多