【问题标题】:how can i use laravel website in CWP (Centos-Web-Panel). without public folder in url?我如何在 CWP(Centos-Web-Panel)中使用 laravel 网站。网址中没有公用文件夹?
【发布时间】:2019-07-28 23:42:46
【问题描述】:

嗨,我想更改我的网站的根目录,服务器面板是 CWP centos-web-panel。我找到了一个解决方案,在httpd.conf 中更改DocumentRootdirectory,但我无法更改它,因为我的很多网站都使用此服务器。我想更改我的一个网站中的根文件夹。 另外,我找到了另一个解决方案,它说编辑文件。

# nano /etc/httpd/conf.d/your_site.conf

并将此代码添加到文件中

<VirtualHost *:80>
DocumentRoot /var/www/html/your_site/public
ServerName your_domain

<Directory /var/www/html/your_site/>
AllowOverride All
</Directory>
</VirtualHost>

但不工作。 我该怎么做? 有任何解决方案或使用.htaccess 或拥有laravel 模板吗?

所以我想将centos-web-panel 中的/public_html/ 更改为/public_html/public/ 我使用 Nginx

【问题讨论】:

  • 将你的 server.php 重命名为 index.php 并从 public 文件夹中复制你的 .htaccess 文件并将其平行粘贴到 index.php(之前是 server.php)
  • @AnkurTiwari 如果我只将server.php 更改为index.php。任何人都可以下载我的.env 类型为www.example.com/.env 的文件,我该如何防止呢?
  • 你也可以隐藏 yours.env,请查看我的回答

标签: php laravel .htaccess nginx centos-web-panel


【解决方案1】:

在 .htaccess 中添加这段代码

重写引擎开启

RewriteRule ^(.*)$ public/$1 [L]

并将 index.php 文件复制到根文件夹并按照步骤操作 https://hellocoding.wordpress.com/2014/05/17/how-to-remove-public-from-url-in-laravel/ https://hdtuto.com/article/laravel-remove-public-from-url-using-htaccess

【讨论】:

    【解决方案2】:

    您需要执行以下操作以在URL 中不公开地指向您的应用程序:

    将您的 server.php 重命名为 index.php 并从公共文件夹中复制您的 .htaccess 文件并将其平行粘贴到 index.php(之前为 server.php

    要隐藏您的 .env 文件,您需要在您的 .htaccess 文件中添加以下行

    # Disable index view
    Options -Indexes
    
    # Hide a specific file
    <Files .env>
        Order allow,deny
        Deny from all
    </Files>
    

    【讨论】:

    • 如何对所有文件和文件夹执行此操作?
    【解决方案3】:

    我更喜欢这个答案。哪个更安全。并且无需重定向。 在 public_html 中创建一个文件夹可能是 foldername 然后将所有文件和文件夹从 public_html 移动到 foldername 之后将所有文件和文件夹从 public laravel 文件夹移动到 public_html 打开 index.php 并编辑像这样。

    require __DIR__.'/../vendor/autoload.php';
    $app = require_once __DIR__.'/../bootstrap/app.php';
    

    require __DIR__.'/foldername/vendor/autoload.php';
    $app = require_once __DIR__.'/foldername/bootstrap/app.php';
    

    然后用.htaccess隐藏.env文件

    完成

    【讨论】:

      【解决方案4】:

      如果您可以访问 ssh 删除 public_html 文件夹 rm -rf public_html/ 创建公共文件夹(laravel)的快捷方式,我们将把laravel放在同级public_html ln -s laravel/public public_html 现在完成了

      【讨论】:

        【解决方案5】:

        转到:

        WebServer Settings -> Conf Editor -> Apache -> /usr/local/apache/conf.d/vhosts/
        

        搜索 mydomain.ssl.confmydomain.conf 并点击 edit

        搜索 DocumentRoot 并更改它

        发件人:

        DocumentRoot /home/username/public_html
        

        收件人:

        DocumentRoot /home/username/public_html/public
        

        之后别忘了重启 Apache。

        完成

        【讨论】:

          猜你喜欢
          • 2015-03-11
          • 2018-07-31
          • 2016-05-23
          • 1970-01-01
          • 2010-09-24
          • 2021-04-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多