系统相关
首页 > 系统相关> > amazon-web-services – 在AWS弹性beanstalk上用nginx和php-fpm替换Apache / PHP

amazon-web-services – 在AWS弹性beanstalk上用nginx和php-fpm替换Apache / PHP

作者:互联网

我一直试图找到有关用bean beanstalk应用程序用nginx和php-fpm替换Apache / 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.

我已经在这个配置上运行了几个小时的环境,并且运行良好.

我希望一切都适合你,因为它(最后)对我而言.

标签:nginx,amazon-web-services,elastic-beanstalk
来源: https://codeday.me/bug/20190830/1769300.html