【问题标题】:Laravel - set /public as root on LAMP stackLaravel - 在 LAMP 堆栈上将 /public 设置为 root
【发布时间】:2018-12-26 14:16:14
【问题描述】:

我正在尝试在 LAMP 堆栈上部署 Laravel 应用程序,尽管我无法将文档根设置为 /public。我已经在这里查看了几个类似问题的答案,但还没有找到我的问题或解决方案。理想情况下,我想通过 Apache Web 服务器来完成,而不是修改任何 Laravel 文件。

我复制了默认的.conf 文件并使用sudo nano /etc/apache2/sites-available/subdomain.website.com.conf 将其更改为以下内容

<VirtualHost *:80>
        ServerAdmin email@gmail.com
        ServerName subdomain.website.com
        ServerAlias www.subdomain.website.com
        DocumentRoot /var/www/subdomain.website.com/public_html/public

        <Directory /var/www/subdomain.website.com/public_html/public/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.subdomain.website.com [OR]
RewriteCond %{SERVER_NAME} =subdomain.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

之后我按此顺序运行以下命令。

sudo a2ensite subdomain.website.com.conf

sudo a2enmod rewrite

sudo systemctl restart apache2

sudo service apache2 restart

我清除了 cookie,进行了硬刷新,但没有奏效。我仍然需要去https://subdomain.website.com/public 才能查看该网站。有什么我错过的或我能做些什么来找出问题所在吗?

/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]

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

【问题讨论】:

    标签: laravel apache lamp


    【解决方案1】:

    此虚拟主机用于 http://(端口 80)。你有一个重写规则,一旦它到达这个虚拟主机就会重定向到 https://。

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.subdomain.website.com [OR]
    RewriteCond %{SERVER_NAME} =subdomain.website.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    

    因此,您需要将更改应用到从 https://(端口 443)为该域提供服务的其他虚拟主机。

    【讨论】:

    • 感谢您抽出宝贵时间回复,您是对的。我运行sudo nano subdomain.website.com-le-ssl.conf 并将/public 附加到必要的行中,一切都很好。再次感谢。
    • 很高兴我能帮上忙。
    猜你喜欢
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    相关资源
    最近更新 更多