proxy_set_header 主机 $host;

proxy_set_header 主机 $host;

我使用 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总是出现 404。该站点可从服务器访问(通过复制粘贴到 lynx 进行验证)。我不明白为什么。日志文件中只有以下内容:/three/four/five

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" "-"

有任何想法吗?

答案1

这个 IP 是什么 - 10.0.1.91???

你检查过你的 DNS 吗?你检查过 Nginx 中没有缓存任何不良内容吗?

我刚刚将其添加到我的 Nginx 配置中

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

并且它有效 :/

PS 把这个拿出来

proxy_set_header 主机 $host;

相关内容