質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

3057閲覧

aws ec2 laravel 404 Not Foundで表示されてしまう。

aoinosuke

総合スコア8

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2020/08/22 13:55

編集2020/08/22 14:11

nginxは起動している。
/var/log/nginx/error.log を見た所

"/var/www/outputer/public/books" failed (2: No such file or directory), client: 164.70.146.42, server: _, request: "GET /books HTTP/1.1", host: "18.182.97.82" "/var/www/outputer/public/404.html" failed (2: No such file or directory), client: 164.70.146.42, server: _, request: "GET /books HTTP/1.1", host: "18.182.97.82"

というエラー。
色々考えて読み込みの権限が通ってないのかと考えています。

https://teratail.com/questions/261397
この記事が自分とそっくりなのでっすが、解決方法がなく困っております。
どなたかよろしくお願いします。

user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80; listen [::]:80; server_name _; root /var/www/outputer/public/; index index.php index.html index.htm; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { try_files $uri $uri/ /index.php$is_args$args; } location ~ .php$ { try_files $uri /index.php =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yu_1985

2020/08/22 14:02

laravelのrouterの設定かnginxの設定が怪しいですね。 なのでそれらを貼ってみてください。 not foundなので権限の問題ではないと思います。
aoinosuke

2020/08/22 14:07

user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf;
aoinosuke

2020/08/22 14:07

server { listen 80; listen [::]:80; server_name _; root /var/www/outputer/public/; index index.php index.html index.htm; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 途中で切れてしまい申し訳ないです。 こちらがnginxの設定です。
yu_1985

2020/08/22 14:08

ここに貼ると読みづらいので、本文にコードブロックで貼ってください。
yu_1985

2020/08/22 14:09

include /etc/nginx/conf.d/*.conf; なので、別のファイルを読み込んでますね。 重要なのはむしろそっちじゃないでしょうか。Laravelを設定するときにnginxの設定をなにか追加しませんでしたか?
aoinosuke

2020/08/22 14:09

<?php use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return redirect('/books'); }); Auth::routes(); Route::get('books', 'booksController@index')->name('books.index'); Route::get('search', 'SearchesController@index')->name('search.index'); #####ユーザー Route::resource('users', 'UsersController',['only' => ['index', 'show']]); // フォロー/フォロワー Route::get('users/{user}/following', 'UsersController@following')->name('users.following'); Route::get('users/{user}/followers', 'UsersController@followers')->name('users.followers'); Route::get('users/{user}/favorites', 'UsersController@favorites')->name('users.favorites'); #ログイン状態 Route::group(['middleware' => 'auth'], function() { #ユーザ関連 Route::resource('users', 'UsersController', ['only' => ['index', 'show', 'edit', 'update', 'destroy']]); // フォロー/フォロー解除を追加 Route::post('users/{user}/follow', 'UsersController@follow')->name('users.follow'); Route::delete('users/{user}/unfollow', 'UsersController@unfollow')->name('users.unfollow'); //投稿記事関連 Route::resource('books', 'booksController',['only' => ['create', 'store', 'edit', 'update', 'destroy']]); //アウトプット Route::resource('sentences', 'sentencesController', ['only' => ['store', 'edit', 'update', 'destroy']]); Route::get('sentences/create/{id}', 'sentencesController@create')->name('sentences.create'); //タグ Route::resource('tags', 'tagsController', ['only' => ['store', 'destroy']]); Route::get('tags/create/{id}', 'TagsController@create')->name('tags.create'); //いいね関連 Route::post('sentences/{sentence}/favorites', 'FavoritesController@store')->name('favorites'); Route::post('sentences/{sentence}/unfavorites', 'FavoritesController@destroy')->name('unfavorites'); }); Route::get('tags/{tag}', 'TagsController@show')->name('tags.show'); Route::get('/fetch', 'BooksController@fetch')->name('book.fetch'); Route::get('books/{book}', 'BooksController@show')->name('books.show'); Route::get('sentences/{sentence}', 'sentencesController@show')->name('sentences.show'); こちらがrooter 関連です。
yu_1985

2020/08/22 14:12

> ここに貼ると読みづらいので、本文にコードブロックで貼ってください。 再掲します。
yu_1985

2020/08/22 14:13

Laravelのソースはどこに置いてありますか?
aoinosuke

2020/08/22 14:14

ご返信ありがとうございます。 申し訳ありません。本文に写します。 include /etc/nginx/conf.d/*.conf;の件ですが、 何かを入れた記憶が無いですがもしかしたら色々操作しているうちに何か設定変えてるのかもしれないです。。 この場合はnginxをreinstallで初期化したほうがよろしいでしょうか。
yu_1985

2020/08/22 14:15

あと、Laravelのログにはなにか出てないですかね。
yu_1985

2020/08/22 14:16

> 何かを入れた記憶が無い 途中で切れた状態のものを見て書いたので、そこの中を編集してないのであればそれでOKです。
aoinosuke

2020/08/22 14:17

laravelのソースは /var/www/に配置しております。 /var/www/outputer という形です。 ログは確認します
aoinosuke

2020/08/23 01:01 編集

早速記事見て cp .env.example .env php artisan key:generate php artisan config:clear を行いました。 変わったことは500エラーページが強制的にhttp://000.000.00.00/booksのページに推移して 404エラーを吐き出しています
guest

回答1

0

ベストアンサー

どこの記事を見て、何に対してどういう対処としてそれを実施したのかがよくわかりませんが…。

変わったことは500エラーページが強制的にhttp://18.182.97.82/booksのページに推移して

nginxで、500番台のエラーページの処理はここです。

error_page 500 502 503 504 /50x.html; location = /50x.html { try_files $uri $uri/ /index.php$is_args$args; }

URIで指定したパスにファイルもディレクトリもないので/index.phpに飛んでるのかと。
Nginxのtry_filesディレクティブ設定例

そして、トップで恐らくindex.phpを表示するようにしていて、そのトップではbooksにリダイレクトしています。

Route::get('/', function () { return redirect('/books'); });

また、エラーページでnginxのバージョンが丸見えです。
nginxの設定のどこかで

server_tokens off;

を設定してください。
HTTPレスポンスヘッダにサーバのバージョンの表示を消す

Laravelのログでは
No application encryption key has been specified.となっていますが、そのエラーに対する対処を下感じですかね…。

ここまで来るとLaravel側がなにかおかしいような気はします。

投稿2020/08/23 09:38

yu_1985

総合スコア7447

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

aoinosuke

2020/08/24 07:24

nginxの設定でうまくいきました。 色々とヒントいただきありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問