2016-11-17 116 views
0

我需要在EB中更改我的nginx反向代理的配置。在我的本地環境中,我配置的都很好,但是當我嘗試更改proxy_cache_path和其他東西時,它不起作用。在AWS Elastic Beanstalk中配置nginx緩存

這是我的本地配置(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" 

我已經配置的文件夾/家的CACH如果我取消註釋proxy_cache_path和Configure Cache部分的行,則部署失敗。

任何想法?我花了超過2小時,沒有結果...謝謝!

回答

0

好吧,我剛剛解決了移動線路輸出服務器:

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

server { ... other code } 

我希望有人幫助我的問題和答案。謝謝!