0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nginx で Laravel をリバースプロキシーで動かす

Last updated at Posted at 2021-02-15

次のプログラムを Nginx で動かして見ました。
Laravel で HelloWorld

注意: この方法では簡単な Laravel プログラムしか動かすことは出来ません。

複雑なプロジェクトの場合は、こちらの方法があります。
Nginx で Laravel を動かす

Larevel サーバーの起動

$ php artisan serve --host 0.0.0.0
Starting Laravel development server: http://0.0.0.0:8000
[Mon Feb 15 09:58:22 2021] PHP 7.4.9 Development Server (http://0.0.0.0:8000) started

curl でアクセスして動いていることを確認

$ curl http://localhost:8000/hello
<h2>Feb/15/2021</h2><!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>My First Page</title>
</head>
<body>
  <h2>Hello World!!</h2>
  <p>皆さん、こんにちは</p>
Feb/15/2021<p />
</body>
</html>

Nginx の設定変更

/etc/nginx/sites-available/devault
server {
(省略)
location  ^~ /hello {
                proxy_pass   http://127.0.0.1:8000/hello;
        }
}

設定ファイルが正しいか確認

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Nginx の再起動

sudo systemctl restart nginx

クライアントからアクセス

curl http://localhost/hello
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?