nginx 的奇怪重定向,包括部分域名

nginx 的奇怪重定向,包括部分域名

由于某些未知的原因,http://utro.ee/nonsense重定向至http://utro.ee/.ee

当应用程序在没有 nginx 的情况下运行时,一切都很好——它会重定向到http://utro.ee

你能告诉我为什么会发生这种情况吗?

来自日志的调试信息:

2014/01/16 10:47:19 [debug] 31895#0: *2427 http cleanup add: 00000000024374F0
2014/01/16 10:47:19 [debug] 31895#0: *2427 get rr peer, try: 1
2014/01/16 10:47:19 [debug] 31895#0: *2427 socket 42
2014/01/16 10:47:19 [debug] 31895#0: *2427 epoll add connection: fd:42 ev:80000005
2014/01/16 10:47:19 [debug] 31895#0: *2427 connect to unix:///tmp/utro.0.sock, fd:42 #2457
2014/01/16 10:47:19 [debug] 31895#0: *2427 connected
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream connect: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 posix_memalign: 0000000002352040:128 @16
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream send request
2014/01/16 10:47:19 [debug] 31895#0: *2427 chain writer buf fl:1 s:1158
2014/01/16 10:47:19 [debug] 31895#0: *2427 chain writer in: 0000000002437528
2014/01/16 10:47:19 [debug] 31895#0: *2427 writev: 1158
2014/01/16 10:47:19 [debug] 31895#0: *2427 chain writer out: 0000000000000000
2014/01/16 10:47:19 [debug] 31895#0: *2427 event timer add: 42: 60000:1389862099358
2014/01/16 10:47:19 [debug] 31895#0: *2427 http finalize request: -4, "/nonsense?" a:1, c:2
2014/01/16 10:47:19 [debug] 31895#0: *2427 http request count:2 blk:0
2014/01/16 10:47:19 [debug] 31895#0: *2427 http run request: "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream check client, write event:1, "/nonsense"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream recv(): -1 (11: Resource temporarily unavailable)
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream request: "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream dummy handler
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream request: "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream dummy handler
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream request: "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream process header
2014/01/16 10:47:19 [debug] 31895#0: *2427 malloc: 0000000002428AB0:4096
2014/01/16 10:47:19 [debug] 31895#0: *2427 recv: fd:42 304 of 4096
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy status 301 "301 Moved Permanently"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header: "Location: http://utro.ee/"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header: "Content-Type: text/html"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header: "Cache-Control: no-cache"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header: "X-Request-Id: dfbfce79-344e-4582-98d9-b3b0fc522e41"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header: "X-Runtime: 0.002762"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header: "Connection: close"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header: "Content-Length: 81"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy header done
2014/01/16 10:47:19 [debug] 31895#0: *2427 rewritten location: "/.ee/"
2014/01/16 10:47:19 [debug] 31895#0: *2427 xslt filter header
2014/01/16 10:47:19 [debug] 31895#0: *2427 HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 16 Jan 2014 08:47:19 GMT
Content-Type: text/html
Content-Length: 81
Location: http://utro.ee/.ee/
Connection: keep-alive
Cache-Control: no-cache
X-Request-Id: dfbfce79-344e-4582-98d9-b3b0fc522e41
X-Runtime: 0.002762

2014/01/16 10:47:19 [debug] 31895#0: *2427 write new buf t:1 f:0 00000000024379E8, pos 00000000024379E8, size: 284 file: 0, size: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 http write filter: l:0 f:0 s:284
2014/01/16 10:47:19 [debug] 31895#0: *2427 http cacheable: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 http proxy filter init s:301 h:0 c:0 l:81
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream process upstream
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe read upstream: 1
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe preread: 81
2014/01/16 10:47:19 [debug] 31895#0: *2427 readv: 1:3792
2014/01/16 10:47:19 [debug] 31895#0: *2427 readv() not ready (11: Resource temporarily unavailable)
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe recv chain: -2
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe buf free s:0 t:1 f:0 0000000002428AB0, pos 0000000002428B8F, size: 81 file: 0, size: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe length: 81
2014/01/16 10:47:19 [debug] 31895#0: *2427 input buf #0
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe write downstream: 1
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe write downstream flush in
2014/01/16 10:47:19 [debug] 31895#0: *2427 http output filter "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http copy filter: "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 image filter
2014/01/16 10:47:19 [debug] 31895#0: *2427 xslt filter body
2014/01/16 10:47:19 [debug] 31895#0: *2427 http postpone filter "/nonsense?" 0000000002437C80
2014/01/16 10:47:19 [debug] 31895#0: *2427 write old buf t:1 f:0 00000000024379E8, pos 00000000024379E8, size: 284 file: 0, size: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 write new buf t:1 f:0 0000000002428AB0, pos 0000000002428B8F, size: 81 file: 0, size: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 http write filter: l:0 f:0 s:365
2014/01/16 10:47:19 [debug] 31895#0: *2427 http copy filter: 0 "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 pipe write downstream done
2014/01/16 10:47:19 [debug] 31895#0: *2427 event timer: 42, old: 1389862099358, new: 1389862099362
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream exit: 0000000000000000
2014/01/16 10:47:19 [debug] 31895#0: *2427 finalize http upstream request: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 finalize http proxy request
2014/01/16 10:47:19 [debug] 31895#0: *2427 free rr peer 1 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 close http upstream connection: 42
2014/01/16 10:47:19 [debug] 31895#0: *2427 free: 0000000002352040, unused: 48
2014/01/16 10:47:19 [debug] 31895#0: *2427 event timer del: 42: 1389862099358
2014/01/16 10:47:19 [debug] 31895#0: *2427 reusable connection: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 http upstream temp fd: -1
2014/01/16 10:47:19 [debug] 31895#0: *2427 http output filter "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http copy filter: "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 image filter
2014/01/16 10:47:19 [debug] 31895#0: *2427 xslt filter body
2014/01/16 10:47:19 [debug] 31895#0: *2427 http postpone filter "/nonsense?" 00007FFF63635EE0
2014/01/16 10:47:19 [debug] 31895#0: *2427 write old buf t:1 f:0 00000000024379E8, pos 00000000024379E8, size: 284 file: 0, size: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 write old buf t:1 f:0 0000000002428AB0, pos 0000000002428B8F, size: 81 file: 0, size: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 write new buf t:0 f:0 0000000000000000, pos 0000000000000000, size: 0 file: 0, size: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 http write filter: l:1 f:0 s:365
2014/01/16 10:47:19 [debug] 31895#0: *2427 http write filter limit 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 writev: 365
2014/01/16 10:47:19 [debug] 31895#0: *2427 http write filter 0000000000000000
2014/01/16 10:47:19 [debug] 31895#0: *2427 http copy filter: 0 "/nonsense?"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http finalize request: 0, "/nonsense?" a:1, c:1
2014/01/16 10:47:19 [debug] 31895#0: *2427 set http keepalive handler
2014/01/16 10:47:19 [debug] 31895#0: *2427 http close request
2014/01/16 10:47:19 [debug] 31895#0: *2427 http log handler
2014/01/16 10:47:19 [debug] 31895#0: *2427 free: 0000000002428AB0
2014/01/16 10:47:19 [debug] 31895#0: *2427 free: 00000000024047C0, unused: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 free: 0000000002436FC0, unused: 394
2014/01/16 10:47:19 [debug] 31895#0: *2427 event timer add: 48: 65000:1389862104362
2014/01/16 10:47:19 [debug] 31895#0: *2427 free: 0000000002405CF0
2014/01/16 10:47:19 [debug] 31895#0: *2427 free: 0000000002402A10
2014/01/16 10:47:19 [debug] 31895#0: *2427 hc free: 0000000000000000 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 hc busy: 0000000002436E30 1
2014/01/16 10:47:19 [debug] 31895#0: *2427 free: 0000000002426AA0
2014/01/16 10:47:19 [debug] 31895#0: *2427 tcp_nodelay
2014/01/16 10:47:19 [debug] 31895#0: *2427 reusable connection: 1
2014/01/16 10:47:19 [debug] 31895#0: *2427 post event 000000000247BF30
2014/01/16 10:47:19 [debug] 31895#0: *2427 delete posted event 000000000247BF30
2014/01/16 10:47:19 [debug] 31895#0: *2427 http keepalive handler
2014/01/16 10:47:19 [debug] 31895#0: *2427 malloc: 0000000002405CF0:1024
2014/01/16 10:47:19 [debug] 31895#0: *2427 recv: fd:48 -1 of 1024
2014/01/16 10:47:19 [debug] 31895#0: *2427 recv() not ready (11: Resource temporarily unavailable)
2014/01/16 10:47:19 [debug] 31895#0: *2427 http keepalive handler
2014/01/16 10:47:19 [debug] 31895#0: *2427 recv: fd:48 1024 of 1024
2014/01/16 10:47:19 [debug] 31895#0: *2427 reusable connection: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 malloc: 0000000002406100:1296
2014/01/16 10:47:19 [debug] 31895#0: *2427 event timer del: 48: 1389862104362
2014/01/16 10:47:19 [debug] 31895#0: *2427 generic phase: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 rewrite phase: 1
2014/01/16 10:47:19 [debug] 31895#0: *2427 test location: "/"
2014/01/16 10:47:19 [debug] 31895#0: *2427 test location: "500.html"
2014/01/16 10:47:19 [debug] 31895#0: *2427 test location: ~ "^/assets/"
2014/01/16 10:47:19 [debug] 31895#0: *2427 using configuration "/"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http cl:-1 max:10485760
2014/01/16 10:47:19 [debug] 31895#0: *2427 rewrite phase: 3
2014/01/16 10:47:19 [debug] 31895#0: *2427 post rewrite phase: 4
2014/01/16 10:47:19 [debug] 31895#0: *2427 generic phase: 5
2014/01/16 10:47:19 [debug] 31895#0: *2427 generic phase: 6
2014/01/16 10:47:19 [debug] 31895#0: *2427 generic phase: 7
2014/01/16 10:47:19 [debug] 31895#0: *2427 access phase: 8
2014/01/16 10:47:19 [debug] 31895#0: *2427 access phase: 9
2014/01/16 10:47:19 [debug] 31895#0: *2427 access phase: 10
2014/01/16 10:47:19 [debug] 31895#0: *2427 post access phase: 11
2014/01/16 10:47:19 [debug] 31895#0: *2427 try files phase: 12
2014/01/16 10:47:19 [debug] 31895#0: *2427 http init upstream, client timer: 0
2014/01/16 10:47:19 [debug] 31895#0: *2427 posix_memalign: 00000000024047C0:4096 @16
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script copy: "Host: "
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script var: "utro.ee"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script copy: "
"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script copy: "X-Real-IP: "
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script var: "91.146.65.25"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script copy: "
"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script copy: "X-Forwarded-for: "
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script var: "91.146.65.25"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script copy: "
"
2014/01/16 10:47:19 [debug] 31895#0: *2427 http script copy: "Connection: close

配置如下:

# cat /etc/nginx/nginx.conf
user www-data;
worker_processes  8;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    include /usr/local/ispmgr/etc/nginx.domain;
    client_max_body_size 16M;
    log_format isp '$bytes_sent $request_length';
}

http {
proxy_read_timeout 500;
proxy_connect_timeout 500;
client_max_body_size 100M;
server_names_hash_bucket_size 64;
}

# cat /etc/nginx/fastcgi_params 

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

# cat /etc/nginx/conf.d/my.conf 
server_tokens off;

# cat sites-available/utro

upstream utro {
  server unix:///tmp/utro.0.sock;
}

server {
  server_name utro.ee www.utro.ee;
  client_max_body_size 10M;
  listen 144.76.79.85;

  rewrite_log on;
  access_log /var/log/nginx/utro_access.log;
  error_log /var/log/nginx/utro_error.log debug;

  location / {
    proxy_pass http://utro;
    proxy_redirect http://utro /;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-for $remote_addr;
    port_in_redirect off;
    proxy_connect_timeout 600;
  }

  location ~ ^/assets/ {
    root /home/utro/app/utro/public;
    gzip_static on;    

    expires 1y;
    add_header Cache-Control public;
    proxy_ignore_headers Cache-Control;

    add_header ETag "";
    break;
  }

  root /home/utro/app/utro/public;

  try_files $uri/index.html $uri.html $uri @app;

  location @app {
    proxy_pass http://utro; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  error_page 500 502 503 504 /500.html;

  location = /500.html {
    #########################################################
    # This should go to the public folder of your rails app #
    #########################################################
    root /home/utro/app/utro/public;
  }
}

答案1

proxy_redirect off;

是关键。

答案2

原因可能如下:

proxy_redirect http://utro /;

您应该保留proxy_redirect其默认值default,关闭它也会导致各种问题,具体取决于您的应用程序(例如,后端可能无法正确添加缺少的尾随斜杠)。

相关内容