2015-11-25 83 views
0

雖然目標受影響的站點位於他們自己的服務器塊中,但我的301個重定向問題指向我們的主站點。如果我禁用主站點,其他站點按預期工作,所以似乎主站點中的某些內容正在爭奪其他站點。任何幫助,將不勝感激。nginx 301重定向到不正確的虛擬主機

/etc/nginx/nginx.conf:

user nginx; 
worker_processes 8; 
worker_rlimit_nofile 100000; 

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

events { 
    worker_connections 4096; 
    multi_accept on; 
    use epoll; 
} 

http { 
    include  /etc/nginx/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/nginx/access.log; 
    access_log off; 
    gzip on; 
    gzip_disable "msie6"; 
    gzip_vary on; 
    gzip_proxied any; 
    gzip_comp_level 6; 
    gzip_min_length 1100; 
    gzip_buffers 16 8k; 
    gzip_http_version 1.1; 
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 
    open_file_cache max=2000 inactive=20s; 
    open_file_cache_valid 60s; 
    open_file_cache_min_uses 5; 
    open_file_cache_errors off; 
    client_max_body_size 50M; 
    client_body_buffer_size 1m; 
    client_body_timeout 15; 
    client_header_timeout 15; 
    keepalive_timeout 2 2; 
    send_timeout 15; 
    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    fastcgi_buffers 256 16k; 
    fastcgi_buffer_size 128k; 
    fastcgi_connect_timeout 3s; 
    fastcgi_send_timeout 120s; 
    fastcgi_read_timeout 120s; 
    fastcgi_busy_buffers_size 256k; 
    fastcgi_max_temp_file_size 0; 
    reset_timedout_connection on; 
    server_names_hash_bucket_size 100; 
    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m; 
    ssl_session_cache shared:SSL:10m; 
    ssl_session_timeout 10m; 
    include /etc/nginx/conf.d/*.conf; 
} 

這是出現要勝過其他虛擬主機虛擬主機CONF。 /etc/nginx/conf.d/site1.conf:

server { 
     listen 10.10.10.1:80; 
     listen 10.10.10.1:443 ssl; 
     server_name ^site1\.org$ ^www\.site1\.org$ ^old\.site1domain\.org$; 
     ssl_certificate ...; 
     ssl_certificate_key ...; 
     ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; 
     ssl_ciphers   HIGH:!aNULL:!MD5; 
     keepalive_timeout 70; 
     root /var/www/vhosts/site1.org/httpdocs; 
     index index.php; 
     client_max_body_size 128M; 
     location ~ \.php$ { 
       try_files $uri =404; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_index index.php; 
       fastcgi_pass unix:/var/run/php-fpm/site1.sock; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       fastcgi_param PATH_INFO $fastcgi_path_info; 
       include /etc/nginx/fastcgi_params; 
       include /etc/nginx/fastcgi.conf; 
       open_file_cache   max=4000 inactive=20s; 
       open_file_cache_valid 30s; 
       open_file_cache_min_uses 2; 
       open_file_cache_errors on; 
     } 
     add_header Strict-Transport-Security "max-age=31536000; includeSubdomains"; 
     if ($scheme != "https") { 
       rewrite^https://site1.org$uri permanent; 
     } 
     if ($host != "site1.org") { 
       rewrite^https://site1.org$uri permanent; 
     } 
     #wp-super-cache 
     .... 
     location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|tar|mid|midi|wav|bmp)$ { 
       expires max; 
     } 

}

唷。好的,下面是一個不同的虛擬主機配置的例子,它似乎沒有回答請求(相反,我得到一個301上面的虛擬主機,有或沒有重定向註釋掉)。

/etc/nginx/conf.d/site2.conf:

server { 
    listen 10.10.10.1:80; 
    server_name ^sub1\.site2\.org$; 
    allow all; 
    proxy_redirect/http://10.10.10.1:6969; 
    location/{ 
      proxy_pass http://10.10.10.1:6969; 
    } 
} 

然而,出於某種原因,這個SSL代理按預期工作(在不同的IP): 的/ etc/nginx的/ conf目錄。 d/site3.conf:

server { 
     listen 10.10.10.2:443 ssl; 
     server_name ^sub3\.site1\.org$; 
     ssl_certificate  ...; 
     ssl_certificate_key ...; 
     ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; 
     ssl_ciphers   HIGH:!aNULL:!MD5; 
     allow all; 
     proxy_redirect/http://sub3.site1.org:80/; 
     location/{ 
      proxy_pass http://sub3.site1.org:80/; 
     } 
     proxy_set_header Host $http_host; 
} 

這裏是我所得到的,當我嘗試連接到http://sub1.site2.org

[C09 79] /etc/nginx/conf.d#wget的{sub1.site2.url } - 2015-11-25 09:09:28-- {sub1.site2.url} 解決sub1.site2.org ... 10.10.10.1 連接到sub1.site2.org | 10.10.10.1 |:80。 .. 連接的。 HTTP請求發送的,在等待響應... 301永久 位置移動:{site1.url} [以下]

等等... 預先感謝。

回答

0

您的server_name指令全部無效,因此它們都不匹配。所以nginx使用第一個server容器作爲默認值,並通過它處理所有請求。

然後它打到你的rewrite^https://site1.org$uri permanent;條件重寫。

如果您必須在您的server_name s中使用正則表達式(儘管效率較低,除非您真的需要它),您必須在名稱前加上~。否則,只需使用普通名稱即可。

server_name site1.org www.site1.org old.site1domain.org; 

有關詳細信息,請參見this document