使用AWS弹性Beanstalk上的nginx和php-fpmreplaceApache / PHP

我一直在试图find关于用AWS beanstalk应用程序的nginx和php-fpmreplaceApache / PHP的最新文档。 不过,我发现的唯一的东西是旧的,它指的是修改hostmanager来完成这个,所以这不再适用。

我可以通过一些努力破解我的方式,但是我很好奇,如果有人最近这样做了,他们的程序是什么?

我也很难找到有关在Elastic Beanstalk上设置NGINX的任何教程或文档。 在今天整天摆弄之后,我想我已经想出了如何成功设置它。

以下是我以设置(以希望)简洁的方式列出的步骤:

1.设置一个EB环境,并找到它所使用的ec2实例之一。 右键单击实例,然后选择“启动更喜欢此”。 继续执行这些步骤来启动一个新的实例。

2. SSH到新启动的实例中,并运行下面的命令(如果你喜欢的话,把它放在一个bash脚本中):

# Remove apache yum remove httpd # install nginx and other needed components yum install \ php54.x86_64 \ php54-bcmath.x86_64 \ php54-cli.x86_64 \ php54-common.x86_64 \ php54-dba.x86_64 \ php54-devel.x86_64 \ php54-fpm.x86_64 \ php54-gd.x86_64 \ php54-intl.x86_64 \ php54-mbstring.x86_64 \ php54-mcrypt.x86_64 \ php54-pdo.x86_64 \ php54-pecl-apc.x86_64 \ php54-process.x86_64 \ php54-xml.x86_64 

然后确保在服务器启动时启动php-fpm和nginx:

 chkconfig php-fpm on chkconfig nginx on 

4:为nginx设置配置。 我在下面复制了我的视频,但是根据您的设置,您的视频可能会略有不同:

 # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes 4; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; 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"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80; server_name localhost; root /var/app/current/public_html; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { # Some basic cache-control for static files to be sent to the browser expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } # main php files location / { index index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } # redirect server error pages to the static page /40x.html # error_page 404 /404.html; location = /40x.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # try_files $uri $uri/ /index.php$is_args$args; # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(.*)$; root /var/app/current/public_html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } # make sure the hostmanager works (this is important for EB) location /_hostmanager/ { proxy_pass http://127.0.0.1:8999/; } } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } 

只要继续,将以上所有内容复制到/etc/nginx/nginx.conf

5:进入到你的实例,右键单击它,选择“创建图像”,它会为你创建一个ami。 然后,您可以进入任何EB应用程序,然后转至配置>实例选项卡,并将AMI更改为您刚刚创建的ami的ID。

我在这个配置上运行了几个小时的环境,运行良好。

我希望一切都适合你,因为它对我来说(最后)。 🙂

编辑:这是我的信息来源: