【问题标题】:how to change index directory of my laravel website如何更改我的 laravel 网站的索引目录
【发布时间】:2019-10-13 19:16:05
【问题描述】:

我想在我的本地主机中使用 Laravel 框架创建一个网站 laragon 服务器

我在虚拟主机中上传了网站文件。当我输入网址http://www.mywebsite.com。然后我就得到像

这样的文件

但是当我输入 url http://www.mywebsite.com/public 时,它工作得很好。

谁能告诉我我做错了什么。

【问题讨论】:

    标签: laravel server localhost hosting host


    【解决方案1】:

    您需要将您的域指向 laravel 的公共文件夹而不是根目录,因为 laravel 在 project folder/public/index.php 中有 index.php,所以您需要指向 project folder/public/

    【讨论】:

    • @mrprogra002.yes 完全正确。将您的域指向该文件夹。它工作正常。
    • @mrprogra002.您使用的是共享主机还是 vps ?
    • 那么您需要联系托管服务提供商将您的主域指向公共文件夹
    • 我的主机中有 2 个网站,主域工作正常,但这是第二个域..
    • 然后您在主机中转到插件域并编辑您的域的根路径
    【解决方案2】:

    假设您将应用程序上传到/var/www/html 目录。您的公用文件夹路径如下所示/var/www/html/public

    那么你的site-available文件代码应该是这样的

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        root /var/www/html/public;
    
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;
    
        server_name www.mywebsite.com;
    
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
    }
    

    您只需要更改root 路径。然后您的网站将按预期正常运行。

    【讨论】:

      【解决方案3】:
      • 我从公共文件夹 (project_folder/public/) 中移动了所有文件

        进入项目文件夹

      • 在 index.php 中我改变了这行:

        • 需要DIR.'/../vendor/autoload.php';
        • $app = require_once DIR.'/../bootstrap/app.php';

          进入:

        • 需要 DIR.'/./vendor/autoload.php';

        • $app = require_once DIR.'/./bootstrap/app.php';

          工作正常 ... 谢谢大家:)

      【讨论】:

        猜你喜欢
        • 2015-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多