【问题标题】:Configure nginx cache in AWS Elastic Beanstalk在 AWS Elastic Beanstalk 中配置 nginx 缓存
【发布时间】:2017-04-01 11:23:25
【问题描述】:

我需要在 EB 中更改我的 nginx 反向代理的配置。在我的本地环境中,我已经全部配置好并且工作正常,但是当我尝试更改 proxy_cache_path 和其他内容时,它无法正常工作。

这是我的本地配置(nginx.conf),这里重要的是proxy_cache_path和配置缓存部分:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    proxy_cache_path /cache/nginx levels=1:2 keys_zone=cache_zone_name:10m;

    server {
        listen       80;
        server_name  mydomain.app, www.mydomain.app;



        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;

            #Config proxy inverse cache
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;

            # Add cache debugging header
            add_header X-Cache-Status $upstream_cache_status;

            # Configure cache
            proxy_cache        cache_zone_name;
            proxy_cache_valid  any 1m;
            proxy_cache_key    $scheme$host$request_uri;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

    include servers/*;
}

我从官方文档中获取并与我的实例进行比较 .ebextensions/proxy.config

files:
  /etc/nginx/conf.d/proxy.conf:
    mode: "000644"
    owner: root
    group: root
    content: |
      upstream nodejs {
        server 127.0.0.1:8081;
        keepalive 256;
      }

      server {
        listen 8080;
        # proxy_cache_path /home levels=1:2 keys_zone=cache_zone_name:10m;
        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
            set $year $1;
            set $month $2;
            set $day $3;
            set $hour $4;
        }
        access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
        access_log  /var/log/nginx/access.log  main;

        location / {
            proxy_pass  http://nodejs;
            proxy_set_header   Connection "";
            proxy_http_version 1.1;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

            # Add cache debugging header
            add_header X-Cache-Status $upstream_cache_status;

            # Configure cache
            # proxy_cache        cache_zone_name;
            # proxy_cache_valid  any 1m;
            # proxy_cache_key    $scheme$host$request_uri;
        }

        gzip on;
        gzip_comp_level 4;
        gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        location /public {
            alias /var/app/current/public;
        }

      }

container_commands:
 removeconfig:
    command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"

我已将文件夹 /home 配置为缓存,如果我取消注释 proxy_cache_path 和 Configure Cache 部分的行,则部署失败。

有什么想法吗?我已经花了 2 个多小时没有结果...谢谢!!

【问题讨论】:

    标签: amazon-web-services nginx amazon-elastic-beanstalk


    【解决方案1】:

    好的,我解决了只是将线路移出服务器:

     proxy_cache_path /home levels=1:2 keys_zone=cache_zone_name:10m;
    
     server { ... other code }
    

    我希望有人帮助我的问题和答案。谢谢!

    【讨论】:

      猜你喜欢
      • 2020-08-27
      • 2015-03-27
      • 2011-08-03
      • 2021-08-22
      • 2021-11-24
      • 2015-11-27
      • 2015-02-23
      • 1970-01-01
      • 2017-11-20
      相关资源
      最近更新 更多