Nginx的提高404采用格式=&GT的时候; “JS”时候、格式、Nginx、GT

2023-09-10 20:15:38 作者:此生杀伐

我上传使用Ajax和一个iFrame图片到我的应用程序。在发展的一切工作就像一个魅力。但在生产Nginx的突然引发一个404错误。当我看着日志,请求嗟Rails应用程序。所以我猜它是与我的Nginx的配置(也许gzip的COM pression)。

有故障的请求被发送给/images.js。

在如何解决这个任何想法?谷歌不能帮我...

我的Nginx的配置:

 服务器{
      听80;
      SERVER_NAME www.myapp.de;
      根/无功/网络/应用程序/ MyApp的/电流/公; #< ---一定要指向公共!
      passenger_enabled上;
      RAILS_ENV生产;

      #设置护栏到期标题:http://craigjolicoeur.com/blog/setting-static-asset-expires-headers-with-nginx-and-passenger
         位置〜* \。?(ICO | CSS | JS | GIF |?JP G | PNG)(?:\ [0-9] +)$ {
           期满最大;
           打破;
         }

      gzip压缩的;
      gzip_http_version 1.0;
      gzip_vary上;
      gzip_comp_level 6;
      gzip_proxied任;
      gzip_types文本/纯文本/ HTML文本/ css的应用程序/ JSON应用程序/ x-j​​avascript的文/ XML应用程序/ XML应用程序/ XML + RSS文/ JavaScript的;
      #确保GZIP不输大gzip压缩的JS和CSS文件
      #看到http://blog.leetsoft.com/2007/7/25/nginx-gzip-ssl
      gzip_buffers 16 8K;

      #这个重写所有的请求到maintenance.html
      #页,如果它存在于文档根。这是Capistrano的?^?^?的
      #禁用Web任务
      如果(-f $ DOCUMENT_ROOT /系统/ maintenance.html){
        改写^ $ /system/maintenance.html去年(*);
        打破;
      }

      #设置文件上传为10Mb的最大尺寸
      client_max_body_size 10M;
      error_page 500 502 503 504 /500.html;
     位置= /500.html {
       根/无功/网络/应用程序/ MyApp的/电流/公;
     }


    }
 

解决方案

Nginx的任期为/images.js请求从根/无功/网络/应用程序/ MyApp的/电流/大众,因为它符合

 位置〜* \。?(ICO | CSS | JS | GIF |?JP G | PNG)(?:\ [0-9] +)$ {
       期满最大;
       打破;
     }
 
nginx和node.js添加https访问

(破指令只适用于AFAIK重写规则,以便它可以被删除)

如果你想为从您需要启用轨该位置轨道/images.js。

I upload images to my App using Ajax and an Iframe. In Development everything works like a charm. But in production Nginx suddenly raises a 404 error. When I look into the log, the request never hits the Rails app. So I guess it has something to do with my Nginx configuration (maybe gzip compression).

The failing requests is send to "/images.js".

Any ideas on how to solve this? Google couldn't help me...

My Nginx config:

server {
      listen 80;
      server_name www.myapp.de;
      root /var/www/apps/myapp/current/public;   # <--- be sure to point to 'public'!
      passenger_enabled on;
      rails_env production;

      # set the rails expires headers: http://craigjolicoeur.com/blog/setting-static-asset-expires-headers-with-nginx-and-passenger
         location ~* \.(ico|css|js|gif|jp?g|png)(\?[0-9]+)?$ {
           expires max;
           break;
         }                                                                                     

      gzip  on;
      gzip_http_version 1.0;
      gzip_vary on;
      gzip_comp_level 6;
      gzip_proxied any;
      gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
      # make sure gzip does not lose large gzipped js or css files
      # see http://blog.leetsoft.com/2007/7/25/nginx-gzip-ssl
      gzip_buffers 16 8k;

      # this rewrites all the requests to the maintenance.html
      # page if it exists in the doc root. This is for capistrano?^?^?s
      # disable web task
      if (-f $document_root/system/maintenance.html) {
        rewrite  ^(.*)$  /system/maintenance.html last;
        break;
      }

      # Set the max size for file uploads to 10Mb
      client_max_body_size 10M;
      error_page   500 502 503 504  /500.html;
     location = /500.html {
       root /var/www/apps/myapp/current/public;
     }


    }

解决方案

nginx will serve the request for /images.js from your root /var/www/apps/myapp/current/public since it matches

     location ~* \.(ico|css|js|gif|jp?g|png)(\?[0-9]+)?$ {
       expires max;
       break;
     }

(the break directive only applies to rewrite rules afaik so it can be removed)

If you want to serve /images.js from rails you need to enable rails for that location.