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?

Laravel ReverbをEC2(Nginx)で使ってみた。

Last updated at Posted at 2025-02-18

概要

Laravel Reverbを使ってAWS EC2(Ubuntu:Nginx)で立ち上げてみました。
ドメイン名が無い段階、https未対応の段階、https対応済みの段階でReverbが動作するのを確認できました。

前提

・Laravelバージョン:11
・AWS EC2(Ubuntu)
・Nginx

設定

.env

一部の変数のみ記載
APP_URL=https://公開しているサイトのIPアドレスかドメイン名
BROADCAST_CONNECTION=reverb
QUEUE_CONNECTION=database
REVERB_APP_ID=*****
REVERB_APP_KEY=*********
REVERB_APP_SECRET=********
REVERB_HOST=公開しているサイトのIPアドレスかドメイン名
REVERB_SERVER_HOST=127.0.0.1 # 設定せずにデフォルトのままでも良い。 
REVERB_SERVER_PORT=8080 # 設定せずにデフォルトのままでも良い
REVERB_PORT=443
REVERB_SCHEME=https

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

Nginxのconf設定

server {
    listen 80;
    listen [::]:80;

   一部省略

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location /app/ {
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        # どちらかを設定
        # .envのREVERB_SERVER_HOST/REVERB_SERVER_PORTを設定していない場合
        proxy_pass http://0.0.0.0:8080;
        # .envのREVERB_SERVER_HOST/REVERB_SERVER_PORTを設定した場合
        proxy_pass http://127.0.0.1:8080; # .envのREVERB_SERVER_HOST/REVERB_SERVER_PORTの値を設定

    }

    location /apps/ {
        上の/app/の設定と同じ設定
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

  以下省略
}

Reverbの起動

supervisorで実行

/etc/supervisor/conf.d/laravel-reverb.conf
[program:laravel-reverb]
process_name=%(program_name)s
command=php /home/ubuntu/***/artisan reverb:start
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
numprocs=1
minfds=10000
user=reverbを起動させるアカウント名
redirect_stderr=true
stdout_logfile=/home/ubuntu/***/storage/logs/reverb.log
stopwaitsecs=3600
stdout_logfile_maxbytes=5MB

https未対応の場合の設定

この設定を本番運用で使うのは駄目だと思います。ご注意ください。

.env

上記の設定と異なる部分のみ記載
APP_URL=http://公開しているサイトのIPアドレスかドメイン名
REVERB_PORT=80
REVERB_SCHEME=http

Nginxのconf設定

上記の設定と同じ

その他

Nginxの設定や.envの設定を変えた時にリフレッシュさせる必要があったけど、それをやらずに苦労してました。
Nginxの再起動とかartisanコマンドを実行しました。artisanコマンドはどれを行うべきかは自身がありません。

php artisan config:clear
php artisan event:clear
php artisan route:clear
php artisan view:clear
php artisan config:cache
php artisan event:cache
php artisan route:cache
php artisan view:cache
npm run build

開発環境はsailを使ったもので、Nginxを使わなかったのですが、開発環境でもNginxを使って動作確認しておけばよかったかもと思いました。

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?