web-dev-qa-db-ja.com

laravel要求されたURLがこのサーバーで見つかりませんでした

Ubuntu 14.04カーネルを使用しています。このサーバーにLaravelアプリケーションをインストールしていました。インストール後、ルートディレクトリをパブリックに設定しようとしました。

Sudo nano /etc/Apache2/sites-available/000-default.conf

ファイルにはこれらのオプションしかありません

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port t$
        # 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/public/

        # 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

ドキュメントルートを次のように変更しました

DocumentRoot /var/www/html/public/

Laravelアプリにアクセスしようとすると、123.xxx.xxx.xxx/を介してホームページが表示され、正常に機能しています。 GET変数もすべて取得します。例:123.xxx.xxx.xxx?type=wefwef

しかし、123.xxx.xxx.xxx/loginなどの他のリンクにアクセスすると、エラーが発生します

Not Found

The requested URL /login/ was not found on this server.

Apache/2.4.7 (Ubuntu) Server at 104.236.234.85 Port 80

Localhostでroutes.phpがうまく機能しています。しかし、このサーバーではそうではありません。私を助けてください。

48
user1012181

これは、vhostにこれを追加して.htaccessを有効にする必要があるようです。

<Directory /var/www/html/public/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

それでもうまくいかない場合は、 mod_rewrite が有効になっていることを確認してください。

変更を行った後、Apacheを再起動することを忘れないでください! (service Apache2 restart

109
lukasgeiter

次を実行して解決しました。Apacheにrewrite.loadというモジュールがあるかどうかを確認します。

cd /etc/Apache2/mods-enabled/

存在しない場合は、次の抜粋を実行します。

Sudo a2enmod rewrite

そうでない場合は、Apache構成ファイルを変更して、「フレンドリURL」の使用を統合します。

Sudo nano /etc/Apache2/Apache2.conf

エディター内で次のコードを見つけます。

<Directory /var/www/> 
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory> 

への変更:

<Directory /var/www/> 
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

その後、次の方法でApacheサーバーを再起動します。

Sudo /etc/init.d/Apache2 restart
43
Lucas Coelho

最初にa2enmod rewriteを有効にし、次にApacheを再起動します

/etc/init.d/Apache2 restart

これらの質問に答えるにはここをクリック

21
Mathesh Raj

または、.htaccessファイルのすべての内容を置き換えることができます

Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

こちらのドキュメントをご覧ください。 https://laravel.com/docs/5.8/installation#web-server-configuration

2
F KIng

問題のバリエーションがまだある場合のすべての回答に加えて、.envファイルを編集し、次のようにAPP_URLをドメイン名に設定します。

 APP_URL=similar_to_my_avatar_link 
1
resizemyimg.com

Httpd.confファイルで、#を削除する必要があります

#LoadModule rewrite_module modules/mod_rewrite.so

#行を削除すると、次のようになります。

LoadModule rewrite_module modules/mod_rewrite.so

Apacheの再起動

0
Masum billah

遅すぎる..しかし、あなたは.htaccessファイルのコメントをこの行に編集することができます

  #  RewriteRule ^ index.php [L]
0
Ahmed khaled

mod_rewriteが有効になっていることを確認してください。

restart Apache

ブラウザのcookiesをクリアして。htaccessで再度読み取ります

0
Miguel Avila R.