【发布时间】:2014-09-25 20:26:55
【问题描述】:
我一直在尝试查找有关用 nginx 和 php-fpm 替换 AWS beanstalk 应用程序的 Apache/PHP 的最新文档。但是,我发现的唯一东西是旧的,它指的是修改主机管理器来实现这一点,所以这不再适用。
我可以通过一些努力来破解它,但我很好奇最近是否有人这样做过,他们的程序是什么?
【问题讨论】:
标签: amazon-web-services nginx amazon-elastic-beanstalk
我一直在尝试查找有关用 nginx 和 php-fpm 替换 AWS beanstalk 应用程序的 Apache/PHP 的最新文档。但是,我发现的唯一东西是旧的,它指的是修改主机管理器来实现这一点,所以这不再适用。
我可以通过一些努力来破解它,但我很好奇最近是否有人这样做过,他们的程序是什么?
【问题讨论】:
标签: amazon-web-services nginx amazon-elastic-beanstalk
我也很难找到任何有关在 Elastic Beanstalk 上设置 NGINX 的教程或文档。今天折腾了一整天,我想我已经知道如何设置成功了。
以下是我设置的步骤,以(希望)简洁的方式列出:
1. 设置一个 EB 环境,并找到它使用的一个 ec2 实例。右键单击该实例并选择“Launch more like this”。继续执行启动新实例的步骤。
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: 转到您要通过 ssh 访问的实例,右键单击它并选择“创建图像”,它会为您创建一个 ami。 然后,您可以进入任何 EB 应用程序并转到配置 > 实例选项卡并将 AMI 更改为您刚刚创建的 ami 的 ID。
我已经在此配置上运行了几个小时的环境,并且运行良好。
我希望一切都对你有用,就像它(最终)对我一样。 :)
编辑:这是我的信息来源:
【讨论】: