最近,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;
}
完整解决方案:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)