Nginx

Nginx 反向代理返回 404

  • February 3, 2011

我使用 Nginx 作為 ArchLinux 鏡像的記憶體代理(以加速內部伺服器建構)。它正確地反向代理四個站點,但在第五個站點返回神秘的 404。

/etc/nginx/conf/nginx.conf:

user http;
worker_processes  2;

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  /var/log/access_log  main;
   error_log   /var/log/error_log  debug;

   sendfile       on;
   tcp_nopush     on;
   tcp_nodelay    off;

   keepalive_timeout  30;

   gzip  on;

   proxy_buffering on;
   proxy_cache_path /srv/http/nginx/proxy levels=1 keys_zone=one:256m inactive=5d max_size=512m;
   proxy_buffer_size 4k;
   proxy_buffers 100 8k;
   proxy_connect_timeout      60;
   proxy_send_timeout         60;
   proxy_read_timeout         60;

   proxy_redirect     off;
   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_cache             one;
   proxy_cache_key         $request_uri;
   proxy_cache_valid       200 301 302 30m;
   proxy_cache_valid       404 1m;
   proxy_cache_valid       any 15m;
   proxy_cache_use_stale   error timeout invalid_header updating;

   include /etc/nginx/vhosts/*.conf;

}

/etc/nginx/vhosts/default.conf:

server {
   listen       80;
   server_name  mirror.example.com;

   location / {
       root   html;
       index  index.html;
   }

   location /one {
       proxy_pass http://www.gtlib.gatech.edu/pub/linux/distributions/archlinux/;
   }

   location /two {
       proxy_pass http://mirrors.xmission.com/archlinux/;
   }

   location /three {
       proxy_pass http://mirror.rit.edu/archlinux/;
   }

   location /four {
       proxy_pass http://lug.mtu.edu/archlinux/ftpfull/;
   }

   location /five {
       proxy_pass http://repo.archlinux.fr/i686/;
   }

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

   # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one
   #
   location ~ /\.ht {
       deny  all;
   }
}

/one, /two, /three, 並且/four工作完美,但/five總是給出 404。該站點可從伺服器訪問(通過複製粘貼到 lynx 中進行驗證)。我不知道為什麼。日誌文件中唯一的內容是:

Nov 12 09:49:54 mirror NginxMirror: 10.0.1.91 - - [12/Nov/2010:09:49:54 -0500] "GET /five HTTP/1.1" 404 257 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12" "-"

有任何想法嗎?

這個 IP 是什麼 - 10.0.1.91 ???

你檢查過你的dns嗎?你檢查過你沒有在 Nginx 中記憶體一些不好的東西嗎?

我剛剛將它添加到我的 Nginx 配置中

location /five {
   proxy_pass http://repo.archlinux.fr/i686/;
}

它有效:/

PS把這個拿出來

proxy_set_header 主機 $host;

引用自:https://serverfault.com/questions/201188