最近 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

慕田峪9158850
TA貢獻1794條經驗 獲得超7個贊
正確的方法是在里面添加這個文件
.platform/nginx/conf.d/elasticbeanstalk/laravel.conf
這是文檔的鏈接:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
- 2 回答
- 0 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消