2017-10-18 58 views
1
nginx version: nginx/1.10.2 
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013 
TLS SNI support enabled 
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' 

下面是常見的配置(nginx.conf,我截斷了一些行)。爲什麼nginx會將我的請求重定向到www。 <upstream> .com?

user nginx; 

http { 
    include  /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    charset utf-8; 

    server_names_hash_bucket_size 128; 
    client_header_buffer_size 16k; 
    large_client_header_buffers 4 32k; 
    client_max_body_size 50m; 

    open_file_cache max=204800 inactive=20s; 
    open_file_cache_min_uses 1; 
    open_file_cache_valid 30s; 

    sendfile on; 
    tcp_nopush  on; 

    keepalive_timeout 65; 
    tcp_nodelay on; 

    gzip on; 
    gzip_comp_level 6; 
    gzip_vary on; 
    gzip_min_length 1000; 
    gzip_proxied any; 
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; 
    gzip_buffers 16 8k; 

    include /etc/nginx/conf.d/*.conf; 
    server_tokens off; 
} 

以下是sub conf。

upstream wls_abc_pool { 
    ip_hash; 
    server wls_abc_1:8006 weight=1 max_fails=3 fail_timeout=10s; 
    server wls_abc_2:8006 weight=1 max_fails=3 fail_timeout=10s; 
} 
server { 
    listen  80; 
    server_name abc.foo.com; 

    location /wls_abc { 
     proxy_pass http://wls_abc_pool; 
     proxy_set_header X-Real-IP  $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Accept-Encoding ""; 
    } 
} 

當我嘗試訪問http://hostname/wls_abc/http://abc.foo.com/wls_abc/,瀏覽器retrun我想正確的頁面。 當我嘗試訪問http://hostname/wls_abchttp://abc.foo.com/wls_abc時,瀏覽器將重定向到http://www.wls_abc_pool.com/wls_abc/,這很奇怪。


  • http://abc.foo.com/wls_abc - >奇怪的重定向
  • http://abc.foo.com/wls_abc/ - >正常
  • http://hostname/wls_abc - >奇怪的重定向
  • http://hostname/wls_abc/ - >正常

回答

0

如果你希望它匹配或沒有結尾的斜線,那麼你需要改變你的位置規則爲正則表達式,somethi吳象:

位置〜^/wls_abc/$ {

簡要說明:

-^- start of input 
- /wls_abc - what to match 
- /? - one or zero/characters 
- $ - end of input. 
相關問題