AWS Elastic Beanstalk + Laravel,Nginx配置 [英] AWS Elastic Beanstalk + Laravel, Nginx Configuration

查看:54
本文介绍了AWS Elastic Beanstalk + Laravel,Nginx配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,AWS开始使用Amazon Linux 2分发Elastic Beanstalk PHP环境,该环境已经放弃了Apache,转而支持Nginx,我一直在尝试正确配置Laravel项目以使其正常工作,过去我只需要添加一些.htaccess即可配置,就是这样,在Nginx上,我似乎无法弄清楚如何使我的应用正常工作,我的第一个问题是反向代理端口,我通过将PORT环境变量设置为80来修复了该问题,但是当我尝试访问时除了/以外,URL的任何路由都会给我一个404 Not Found错误.

Recently AWS started distributing the Elastic Beanstalk PHP environment with Amazon Linux 2, which has dropped apache in favor of Nginx, I've been trying to correctly configure my Laravel project to work, I used to just have to add some .htaccess configuration and that was it, on Nginx I can't seem to figure out how to make my app to work, my first issue was the reverse proxy port, which I fixed by setting PORT environment variable to 80, but when I try to access any route from the URL aside from /, it gives me an 404 Not Found error.

所以我尝试将.ebextension/Nginx/nginx.conf添加到包含以下内容的项目中:

so I tried to add a .ebextension/Nginx/nginx.conf to my project containing the following:

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并没有改变.

but it didn't work, I tried to check if the configs ware applied on the instance, but /etc/Nginx/Nginx.conf did not change.

如何通过.ebextensions配置Elastic Beanstalk PHP Amazon Linux 2,以使Nginx与无状态Laravel应用程序一起工作?

How can I configure an Elastic Beanstalk PHP Amazon Linux 2 through .ebextensions to make Nginx work with a stateless Laravel application?

谢谢!

推荐答案

我手动将文件添加到/etc/nginx/conf.d/elasticbeanstalk/中,并将其命名为laravel.conf.laravel.conf文件包含:

I manually added a file to /etc/nginx/conf.d/elasticbeanstalk/ and named it laravel.conf. The laravel.conf file contained:

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

完整解决方案:

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

这篇关于AWS Elastic Beanstalk + Laravel,Nginx配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆