![](/img/trans.png)
[英]Custom nginx configuration for Laravel in AWS Elastic Beanstalk
[英]AWS Elastic Beanstalk + Laravel, Nginx Configuration
最近 AWS 開始使用 Amazon Linux 2 分發 Elastic Beanstalk PHP 環境,它已經放棄了 apache,取而代之的是 Nginx,我一直在嘗試正確配置我的 Laravel 項目,我以前只需要添加一些 8314280935 配置它,在 Nginx 我似乎無法弄清楚如何讓我的應用程序工作,我的第一個問題是反向代理端口,我通過將 PORT 環境變量設置為 80 來修復它,但是當我嘗試從URL 除了 /,它給我一個 404 Not Found 錯誤。
所以我嘗試將 a.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;
}
access_log /var/log/nginx/access.log main;
client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
gzip_comp_level 4;
# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/01_static.conf;
include conf.d/elasticbeanstalk/healthd.conf;
}
}
但它沒有用,我試圖檢查實例上是否應用了配置,但 /etc/Nginx/Nginx.conf 沒有改變。
如何通過 .ebextensions 配置 Elastic Beanstalk PHP Amazon Linux 2 以使 Nginx 與無狀態 Laravel 應用程序一起使用?
謝謝你!
我手動將一個文件添加到 /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
正確的方法是在里面添加這個文件
.platform/nginx/conf.d/elasticbeanstalk/laravel.conf
這是文檔的鏈接:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
正確的做法是在 laravel 項目的根目錄中創建以下文件夾結構
.platform/nginx/conf.d/elasticbeanstalk/laravel.conf(或任何其他以.conf結尾的文件名)並輸入以下代碼:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.