【问题标题】:Laravel Project on EC2 instance showing either directory structure or Error 404EC2 实例上的 Laravel 项目显示目录结构或错误 404
【发布时间】:2021-04-10 13:16:05
【问题描述】:

我已经使用 Ubuntu v. 20.04.1 LTS 设置了一个 EC2 实例。我从 Gitlab 克隆了一个现有的 Laravel 项目,该项目在本地 WAMP 上运行得非常好。

我需要一些有关 Apache 虚拟主机和 .htaccess 配置的帮助,因为根据我的尝试,我会得到目录结构或旧的 404 错误。

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/demo/public
    <Directory "/var/www/html/demo/public">
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

/var/www/html/demo/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

/var/www/html/demo/public/.htaccess

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我已经尝试了这些的所有常见变体。使用上面给出的特定配置,我得到一个错误 404。

我已经启用了重写模块,所以这不是问题。

请帮忙!!

【问题讨论】:

    标签: laravel apache .htaccess amazon-ec2 deployment


    【解决方案1】:

    默认情况下,/etc/apache2/sites-available 中的配置未启用或将被忽略。您需要设置启用以创建指向/etc/apache2/sites-enabled 的符号链接。尝试运行此命令:

    sudo a2dissite 000-default
    sudo a2ensite 000-default
    sudo systemctl restart apache2
    

    但我认为define domain/virtual host 比使用 000-default 更好

    【讨论】:

    • 我都试过了..使用了默认值并定义了另一个。是的,我记得也启用了它们
    猜你喜欢
    • 2020-05-07
    • 2015-08-02
    • 2013-06-18
    • 2016-04-11
    • 2014-06-25
    • 2021-03-31
    • 2019-01-04
    • 1970-01-01
    • 2016-07-26
    相关资源
    最近更新 更多