亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AWS Elastic Beanstalk + Laravel、Nginx 配置

AWS Elastic Beanstalk + Laravel、Nginx 配置

PHP
慕后森 2023-03-11 13:46:08
最近 AWS 開始使用 Amazon Linux 2 分發 Elastic Beanstalk PHP 環境,它放棄了 apache 以支持 Nginx,我一直在嘗試正確配置我的 Laravel 項目以使其正常工作,我過去只需要添加一些 .htaccess 配置即可是嗎,在 Nginx 上我似乎無法弄清楚如何讓我的應用程序工作,我的第一個問題是反向代理端口,我通過將 PORT 環境變量設置為 80 來修復它,但是當我嘗試訪問任何路由時除了 / 之外的 URL,它給了我一個 404 Not Found 錯誤。所以我嘗試將 .ebextension/Nginx/nginx.conf 添加到我的項目中,其中包含以下內容:user                    nginx;error_log               /var/log/nginx/error.log warn;pid                     /var/run/nginx.pid;worker_processes        auto;worker_rlimit_nofile    33282;events {    worker_connections  1024;}http {  include       /etc/nginx/mime.types;  default_type  application/octet-stream;  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                    '$status $body_bytes_sent "$http_referer" '                    '"$http_user_agent" "$http_x_forwarded_for"';  include       conf.d/*.conf;  map $http_upgrade $connection_upgrade {      default     "upgrade";  }  server {      listen 80 default_server;      root /var/app/current/public;      location / {           try_files $uri $uri/ /index.php?$query_string;      }      location = /favicon.ico { access_log off; log_not_found off; }      location = /robots.txt  { access_log off; log_not_found off; }      error_page 404 /index.php;      location ~ \.php$ {        fastcgi_pass unix:/var/run/php-fpm/www.sock;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;        include fastcgi_params;      }      location ~ /\.(?!well-known).* {         deny all;      }  }}但它沒有用,我試圖檢查實例上是否應用了配置,但 /etc/Nginx/Nginx.conf 沒有改變。如何通過 .ebextensions 配置 Elastic Beanstalk PHP Amazon Linux 2 以使 Nginx 與無狀態 Laravel 應用程序一起工作?
查看完整描述

2 回答

?
斯蒂芬大帝

TA貢獻1827條經驗 獲得超8個贊

我在 /etc/nginx/conf.d/elasticbeanstalk/ 中手動添加了一個文件,并將其命名為 laravel.conf。laravel.conf 文件包含:

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

完整解決方案:

https://forums.aws.amazon.com/thread.jspa?threadID=321787&tstart=0


查看完整回答
反對 回復 2023-03-11
?
慕田峪9158850

TA貢獻1794條經驗 獲得超7個贊

正確的方法是在里面添加這個文件

.platform/nginx/conf.d/elasticbeanstalk/laravel.conf

這是文檔的鏈接:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html


查看完整回答
反對 回復 2023-03-11
  • 2 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號