[最近,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;
}
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