在反向代理模式下使用NGINX压缩资产(Compressing assets with NGINX in reverse proxy mode)
我在Node.js应用程序前面使用NGINX作为反向代理。 基本代理工作得非常好,我能够使用
compression
中间件compression
节点服务器上的资产。为了测试是否可以将压缩任务委托给NGINX,我已经禁用了中间件,现在我正在尝试使用以下配置使用NGINX进行gzip:
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 300; server { listen 80; ## gzip config gzip on; gzip_min_length 1000; gzip_comp_level 5; gzip_proxied any; gzip_vary on; gzip_types text/plain text/css text/javascript image/gif image/png image/jpeg image/svg+xml image/x-icon; location / { proxy_pass http://app:3000/; 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; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; } } }
使用此配置,NGINX不会压缩资产。 我尝试在
location
上下文中使用不同的选项声明这些,但它们似乎都没有。我找不到相关的资源,所以我在质疑它是否可以这样做。
重点:
1-节点和NGINX在不同的容器上,所以我不使用NGINX服务静态资产。 我只是代理服务这些文件的节点服务器。 我想要实现的是卸载节点服务器,让NGINX进行gzipping。
2-我正在使用“Accept-Encoding:gzip”启用测试所有响应。
I'm using NGINX as a reverse proxy in front of a Node.js app. The basic proxy works perfectly fine and I'm able to compress assets on the Node server with
compression
middleware.To test if it's possible to delegate the compression task to NGINX, I've disabled the middleware and now I'm trying to gzip with NGINX with the following configuration:
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 300; server { listen 80; ## gzip config gzip on; gzip_min_length 1000; gzip_comp_level 5; gzip_proxied any; gzip_vary on; gzip_types text/plain text/css text/javascript image/gif image/png image/jpeg image/svg+xml image/x-icon; location / { proxy_pass http://app:3000/; 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; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; } } }
With this configuration, NGINX doesn't compress the assets. I've tried declaring these in the
location
context with different options but none of them seems to do the trick.I couldn't find relevant resources on this so I'm questioning if it could be done this way at all.
Important points:
1- Node and NGINX are on different containers so I'm not serving the static assets with NGINX. I'm just proxying to the node server which is serving these files. All I'm trying to achieve is offload the node server with getting NGINX to do the gzipping.
2- I'm testing all the responses with "Accept-Encoding: gzip" enabled.
原文:https://stackoverflow.com/questions/46531021
最满意答案
这个错误是由于你的bundle中没有overlayView命名的.xib文件,创建一个新文件 - > UserInterface - > View - >(重命名它OverlayView)现在得到OverlayView并选择视图将其类更改为OverlayView。
this error is due to there is no overlayView named .xib file in your bundle, create a new file -> UserInterface -> View -> (rename it OverlayView) now got OverlayView and select view there change its class to OverlayView.
相关问答
更多-
我是通过使用NSDictionary完成的。 我将自定义类的对象传递给NSDictionary,然后通过NSDictionary设置UITableviewCell的文本。 NSDictionary *dictionary = (NSDictionary *)[usersArray objectAtIndex:indexPath.row]; ((UILabel *)[cell viewWithTag:19]).text = [dictionary objectForKey:@"firstName"]; (( ...
-
通常,当您尝试访问NSArray边界之外的索引处的元素时,会发生这种情况。 所以说你有这样的NSArray : NSArray *a = [NSArray arrayWithObjects:@"a", @"b", @"c", nil]; 此代码将打印“数组索引越界”,因为边界是0 - 2: @try { NSString *string = [a objectAtIndex:3]; } @catch(NSRangeException *e) { NSLog(@"Array index out ...
-
看起来您的XIB(或Storyboard)仍然具有对HelloThereViewController的引用。 在Xcode中更新它可能是最安全的,但您也可以通过在文本编辑器中打开XIB文件来进行搜索和替换。 It looks as though your XIB (or Storyboard) still has a reference to HelloThereViewController. Probably safest to update it in Xcode but you might also ...
-
通过调用初始化视图控制器时 [[GroupDetailViewController alloc] initWithNibName:@"GroupDetailViewController" bundle:nil]; 我们期待您提供相应的xib(“GroupDetailViewController”)。 如果您不想使用xib,只需致电 [[GroupDetailViewController alloc] init] 并在GroupDetailViewController类中实现loadView 。 When ...
-
检查代码中的这一行 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES); 并将其与此进行比较 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 原因是您在NSSearchPathForDirectoriesIn ...
-
这个错误是由于你的bundle中没有overlayView命名的.xib文件,创建一个新文件 - > UserInterface - > View - >(重命名它OverlayView)现在得到OverlayView并选择视图将其类更改为OverlayView。 this error is due to there is no overlayView named .xib file in your bundle, create a new file -> UserInterface -> View -> ...
-
问题很简单。 当您重新加载表时,您mainArray添加5个对象,但只能通过insertRowsAtIndexPaths:在表视图中插入一行。 这些需要匹配。 插入添加到mainArray行mainArray 。 The problem is simple. When you reload the table, you are adding 5 objects to your mainArray but you only insert one row into the table view via inse ...
-
这就是问题。 UIImageView *imageView = [[UIImage alloc] initWithImage:image]; 用此替换它 UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; This is the problem. UIImageView *imageView = [[UIImage alloc] initWithImage:image]; Replace this with this ...
-
似乎odatagen并没有考虑Mac用户。 odatagen依赖于存在的文件 .../ProjectFiles/Framework/src/odatagen/ 目录。 因此,如果在XCode中打开... / ProjectFiles / Framework / src / odatagen / odatagen.xcodeproj并编译,则导航到它应该工作的新odatagen可执行文件。 但是,如果你像我一样并且没有编译到默认位置,那么它仍然无法工作。 odatagen需要其路径包括 .../Proje ...
-
在调用endUpdates之前,您需要确保已将其他记录添加到self.entries 。 例外情况是告诉您,您尝试添加第11行,但numberOfRowsInSection返回10 您需要确保插入与添加到数组中的元素相同的行数 你的更新方法应该是 [self.tableView beginUpdates]; NSMutableArray *newIndices=[NSMutableArray new]; for (id record in p.appRecordList) { [self.entr ...